Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1 | /* drivers/net/ethernet/freescale/gianfar.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Gianfar Ethernet Driver |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 4 | * This driver is designed for the non-CPM ethernet controllers |
| 5 | * on the 85xx and 83xx family of integrated processors |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Based on 8260_io/fcc_enet.c |
| 7 | * |
| 8 | * Author: Andy Fleming |
Kumar Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 9 | * Maintainer: Kumar Gala |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 10 | * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 12 | * Copyright 2002-2009, 2011-2013 Freescale Semiconductor, Inc. |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 13 | * Copyright 2007 MontaVista Software, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License as published by the |
| 17 | * Free Software Foundation; either version 2 of the License, or (at your |
| 18 | * option) any later version. |
| 19 | * |
| 20 | * Gianfar: AKA Lambda Draconis, "Dragon" |
| 21 | * RA 11 31 24.2 |
| 22 | * Dec +69 19 52 |
| 23 | * V 3.84 |
| 24 | * B-V +1.62 |
| 25 | * |
| 26 | * Theory of operation |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 27 | * |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 28 | * The driver is initialized through of_device. Configuration information |
| 29 | * is therefore conveyed through an OF-style device tree. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
| 31 | * The Gianfar Ethernet Controller uses a ring of buffer |
| 32 | * descriptors. The beginning is indicated by a register |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 33 | * pointing to the physical address of the start of the ring. |
| 34 | * The end is determined by a "wrap" bit being set in the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * last descriptor of the ring. |
| 36 | * |
| 37 | * When a packet is received, the RXF bit in the |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 38 | * IEVENT register is set, triggering an interrupt when the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * corresponding bit in the IMASK register is also set (if |
| 40 | * interrupt coalescing is active, then the interrupt may not |
| 41 | * happen immediately, but will wait until either a set number |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 42 | * of frames or amount of time have passed). In NAPI, the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * interrupt handler will signal there is work to be done, and |
Francois Romieu | 0aa1538 | 2008-07-11 00:33:52 +0200 | [diff] [blame] | 44 | * exit. This method will start at the last known empty |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 45 | * descriptor, and process every subsequent descriptor until there |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | * are none left with data (NAPI will stop after a set number of |
| 47 | * packets to give time to other tasks, but will eventually |
| 48 | * process all the packets). The data arrives inside a |
| 49 | * pre-allocated skb, and so after the skb is passed up to the |
| 50 | * stack, a new skb must be allocated, and the address field in |
| 51 | * the buffer descriptor must be updated to indicate this new |
| 52 | * skb. |
| 53 | * |
| 54 | * When the kernel requests that a packet be transmitted, the |
| 55 | * driver starts where it left off last time, and points the |
| 56 | * descriptor at the buffer which was passed in. The driver |
| 57 | * then informs the DMA engine that there are packets ready to |
| 58 | * be transmitted. Once the controller is finished transmitting |
| 59 | * the packet, an interrupt may be triggered (under the same |
| 60 | * conditions as for reception, but depending on the TXF bit). |
| 61 | * The driver then cleans up the buffer. |
| 62 | */ |
| 63 | |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 64 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 65 | #define DEBUG |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/string.h> |
| 69 | #include <linux/errno.h> |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 70 | #include <linux/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #include <linux/slab.h> |
| 72 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include <linux/delay.h> |
| 74 | #include <linux/netdevice.h> |
| 75 | #include <linux/etherdevice.h> |
| 76 | #include <linux/skbuff.h> |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 77 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include <linux/spinlock.h> |
| 79 | #include <linux/mm.h> |
Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 80 | #include <linux/of_address.h> |
| 81 | #include <linux/of_irq.h> |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 82 | #include <linux/of_mdio.h> |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 83 | #include <linux/of_platform.h> |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 84 | #include <linux/ip.h> |
| 85 | #include <linux/tcp.h> |
| 86 | #include <linux/udp.h> |
Kumar Gala | 9c07b884 | 2006-01-11 11:26:25 -0800 | [diff] [blame] | 87 | #include <linux/in.h> |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 88 | #include <linux/net_tstamp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | #include <asm/io.h> |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 91 | #ifdef CONFIG_PPC |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 92 | #include <asm/reg.h> |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 93 | #include <asm/mpc85xx.h> |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 94 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #include <asm/irq.h> |
| 96 | #include <asm/uaccess.h> |
| 97 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #include <linux/dma-mapping.h> |
| 99 | #include <linux/crc32.h> |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 100 | #include <linux/mii.h> |
| 101 | #include <linux/phy.h> |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 102 | #include <linux/phy_fixed.h> |
| 103 | #include <linux/of.h> |
David Daney | 4b6ba8a | 2010-10-26 15:07:13 -0700 | [diff] [blame] | 104 | #include <linux/of_net.h> |
Claudiu Manoil | fd31a95 | 2014-10-07 10:44:31 +0300 | [diff] [blame] | 105 | #include <linux/of_address.h> |
| 106 | #include <linux/of_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | #include "gianfar.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | #define TX_TIMEOUT (1*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 112 | const char gfar_driver_version[] = "1.3"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static int gfar_enet_open(struct net_device *dev); |
| 115 | static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 116 | static void gfar_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static void gfar_timeout(struct net_device *dev); |
| 118 | static int gfar_close(struct net_device *dev); |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 119 | static void gfar_alloc_rx_buffs(struct gfar_priv_rx_q *rx_queue, |
| 120 | int alloc_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | static int gfar_set_mac_address(struct net_device *dev); |
| 122 | static int gfar_change_mtu(struct net_device *dev, int new_mtu); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 123 | static irqreturn_t gfar_error(int irq, void *dev_id); |
| 124 | static irqreturn_t gfar_transmit(int irq, void *dev_id); |
| 125 | static irqreturn_t gfar_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static void adjust_link(struct net_device *dev); |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 127 | static noinline void gfar_update_link_state(struct gfar_private *priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int init_phy(struct net_device *dev); |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 129 | static int gfar_probe(struct platform_device *ofdev); |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 130 | static int gfar_remove(struct platform_device *ofdev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 131 | static void free_skb_resources(struct gfar_private *priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static void gfar_set_multi(struct net_device *dev); |
| 133 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 134 | static void gfar_configure_serdes(struct net_device *dev); |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 135 | static int gfar_poll_rx(struct napi_struct *napi, int budget); |
| 136 | static int gfar_poll_tx(struct napi_struct *napi, int budget); |
| 137 | static int gfar_poll_rx_sq(struct napi_struct *napi, int budget); |
| 138 | static int gfar_poll_tx_sq(struct napi_struct *napi, int budget); |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 139 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 140 | static void gfar_netpoll(struct net_device *dev); |
| 141 | #endif |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 142 | int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit); |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 143 | static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue); |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 144 | static void gfar_process_frame(struct net_device *ndev, struct sk_buff *skb); |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 145 | static void gfar_halt_nodisable(struct gfar_private *priv); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 146 | static void gfar_clear_exact_match(struct net_device *dev); |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 147 | static void gfar_set_mac_for_addr(struct net_device *dev, int num, |
| 148 | const u8 *addr); |
Andy Fleming | 26ccfc3 | 2009-03-10 12:58:28 +0000 | [diff] [blame] | 149 | static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | MODULE_AUTHOR("Freescale Semiconductor, Inc"); |
| 152 | MODULE_DESCRIPTION("Gianfar Ethernet Driver"); |
| 153 | MODULE_LICENSE("GPL"); |
| 154 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 155 | static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 156 | dma_addr_t buf) |
| 157 | { |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 158 | u32 lstatus; |
| 159 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 160 | bdp->bufPtr = cpu_to_be32(buf); |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 161 | |
| 162 | lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 163 | if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1) |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 164 | lstatus |= BD_LFLAG(RXBD_WRAP); |
| 165 | |
Claudiu Manoil | d55398b | 2014-10-07 10:44:35 +0300 | [diff] [blame] | 166 | gfar_wmb(); |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 167 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 168 | bdp->lstatus = cpu_to_be32(lstatus); |
Anton Vorontsov | 8a102fe | 2009-10-12 06:00:37 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 171 | static void gfar_init_bds(struct net_device *ndev) |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 172 | { |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 173 | struct gfar_private *priv = netdev_priv(ndev); |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 174 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 175 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 176 | struct gfar_priv_rx_q *rx_queue = NULL; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 177 | struct txbd8 *txbdp; |
Kevin Hao | 03366a33 | 2014-12-24 14:05:45 +0800 | [diff] [blame] | 178 | u32 __iomem *rfbptr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 179 | int i, j; |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 180 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 181 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 182 | tx_queue = priv->tx_queue[i]; |
| 183 | /* Initialize some variables in our dev structure */ |
| 184 | tx_queue->num_txbdfree = tx_queue->tx_ring_size; |
| 185 | tx_queue->dirty_tx = tx_queue->tx_bd_base; |
| 186 | tx_queue->cur_tx = tx_queue->tx_bd_base; |
| 187 | tx_queue->skb_curtx = 0; |
| 188 | tx_queue->skb_dirtytx = 0; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 189 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 190 | /* Initialize Transmit Descriptor Ring */ |
| 191 | txbdp = tx_queue->tx_bd_base; |
| 192 | for (j = 0; j < tx_queue->tx_ring_size; j++) { |
| 193 | txbdp->lstatus = 0; |
| 194 | txbdp->bufPtr = 0; |
| 195 | txbdp++; |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 198 | /* Set the last descriptor in the ring to indicate wrap */ |
| 199 | txbdp--; |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 200 | txbdp->status = cpu_to_be16(be16_to_cpu(txbdp->status) | |
| 201 | TXBD_WRAP); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 204 | rfbptr = ®s->rfbptr0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 205 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 206 | rx_queue = priv->rx_queue[i]; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 207 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 208 | rx_queue->next_to_clean = 0; |
| 209 | rx_queue->next_to_use = 0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 210 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 211 | /* make sure next_to_clean != next_to_use after this |
| 212 | * by leaving at least 1 unused descriptor |
| 213 | */ |
| 214 | gfar_alloc_rx_buffs(rx_queue, gfar_rxbd_unused(rx_queue)); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 215 | |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 216 | rx_queue->rfbptr = rfbptr; |
| 217 | rfbptr += 2; |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 218 | } |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int gfar_alloc_skb_resources(struct net_device *ndev) |
| 222 | { |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 223 | void *vaddr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 224 | dma_addr_t addr; |
| 225 | int i, j, k; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 226 | struct gfar_private *priv = netdev_priv(ndev); |
Claudiu Manoil | 369ec16 | 2013-02-14 05:00:02 +0000 | [diff] [blame] | 227 | struct device *dev = priv->dev; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 228 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 229 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 230 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 231 | priv->total_tx_ring_size = 0; |
| 232 | for (i = 0; i < priv->num_tx_queues; i++) |
| 233 | priv->total_tx_ring_size += priv->tx_queue[i]->tx_ring_size; |
| 234 | |
| 235 | priv->total_rx_ring_size = 0; |
| 236 | for (i = 0; i < priv->num_rx_queues; i++) |
| 237 | priv->total_rx_ring_size += priv->rx_queue[i]->rx_ring_size; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 238 | |
| 239 | /* Allocate memory for the buffer descriptors */ |
Anton Vorontsov | 8728327 | 2009-10-12 06:00:39 +0000 | [diff] [blame] | 240 | vaddr = dma_alloc_coherent(dev, |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 241 | (priv->total_tx_ring_size * |
| 242 | sizeof(struct txbd8)) + |
| 243 | (priv->total_rx_ring_size * |
| 244 | sizeof(struct rxbd8)), |
| 245 | &addr, GFP_KERNEL); |
| 246 | if (!vaddr) |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 247 | return -ENOMEM; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 248 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 249 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 250 | tx_queue = priv->tx_queue[i]; |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 251 | tx_queue->tx_bd_base = vaddr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 252 | tx_queue->tx_bd_dma_base = addr; |
| 253 | tx_queue->dev = ndev; |
| 254 | /* enet DMA only understands physical addresses */ |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 255 | addr += sizeof(struct txbd8) * tx_queue->tx_ring_size; |
| 256 | vaddr += sizeof(struct txbd8) * tx_queue->tx_ring_size; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 257 | } |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 258 | |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 259 | /* Start the rx descriptor ring where the tx ring leaves off */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 260 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 261 | rx_queue = priv->rx_queue[i]; |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 262 | rx_queue->rx_bd_base = vaddr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 263 | rx_queue->rx_bd_dma_base = addr; |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 264 | rx_queue->ndev = ndev; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 265 | addr += sizeof(struct rxbd8) * rx_queue->rx_ring_size; |
| 266 | vaddr += sizeof(struct rxbd8) * rx_queue->rx_ring_size; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 267 | } |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 268 | |
| 269 | /* Setup the skbuff rings */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 270 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 271 | tx_queue = priv->tx_queue[i]; |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 272 | tx_queue->tx_skbuff = |
| 273 | kmalloc_array(tx_queue->tx_ring_size, |
| 274 | sizeof(*tx_queue->tx_skbuff), |
| 275 | GFP_KERNEL); |
| 276 | if (!tx_queue->tx_skbuff) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 277 | goto cleanup; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 278 | |
| 279 | for (k = 0; k < tx_queue->tx_ring_size; k++) |
| 280 | tx_queue->tx_skbuff[k] = NULL; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 283 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 284 | rx_queue = priv->rx_queue[i]; |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 285 | rx_queue->rx_skbuff = |
| 286 | kmalloc_array(rx_queue->rx_ring_size, |
| 287 | sizeof(*rx_queue->rx_skbuff), |
| 288 | GFP_KERNEL); |
| 289 | if (!rx_queue->rx_skbuff) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 290 | goto cleanup; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 291 | |
| 292 | for (j = 0; j < rx_queue->rx_ring_size; j++) |
| 293 | rx_queue->rx_skbuff[j] = NULL; |
| 294 | } |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 295 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 296 | gfar_init_bds(ndev); |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 297 | |
| 298 | return 0; |
| 299 | |
| 300 | cleanup: |
| 301 | free_skb_resources(priv); |
| 302 | return -ENOMEM; |
| 303 | } |
| 304 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 305 | static void gfar_init_tx_rx_base(struct gfar_private *priv) |
| 306 | { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 307 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Anton Vorontsov | 18294ad | 2009-11-04 12:53:00 +0000 | [diff] [blame] | 308 | u32 __iomem *baddr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 309 | int i; |
| 310 | |
| 311 | baddr = ®s->tbase0; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 312 | for (i = 0; i < priv->num_tx_queues; i++) { |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 313 | gfar_write(baddr, priv->tx_queue[i]->tx_bd_dma_base); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 314 | baddr += 2; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | baddr = ®s->rbase0; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 318 | for (i = 0; i < priv->num_rx_queues; i++) { |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 319 | gfar_write(baddr, priv->rx_queue[i]->rx_bd_dma_base); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 320 | baddr += 2; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 324 | static void gfar_init_rqprm(struct gfar_private *priv) |
| 325 | { |
| 326 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
| 327 | u32 __iomem *baddr; |
| 328 | int i; |
| 329 | |
| 330 | baddr = ®s->rqprm0; |
| 331 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 332 | gfar_write(baddr, priv->rx_queue[i]->rx_ring_size | |
| 333 | (DEFAULT_RX_LFC_THR << FBTHR_SHIFT)); |
| 334 | baddr++; |
| 335 | } |
| 336 | } |
| 337 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 338 | static void gfar_rx_buff_size_config(struct gfar_private *priv) |
| 339 | { |
Claudiu Manoil | f5b720b | 2014-10-15 19:11:46 +0300 | [diff] [blame] | 340 | int frame_size = priv->ndev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 341 | |
| 342 | /* set this when rx hw offload (TOE) functions are being used */ |
| 343 | priv->uses_rxfcb = 0; |
| 344 | |
| 345 | if (priv->ndev->features & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX)) |
| 346 | priv->uses_rxfcb = 1; |
| 347 | |
| 348 | if (priv->hwts_rx_en) |
| 349 | priv->uses_rxfcb = 1; |
| 350 | |
| 351 | if (priv->uses_rxfcb) |
| 352 | frame_size += GMAC_FCB_LEN; |
| 353 | |
| 354 | frame_size += priv->padding; |
| 355 | |
| 356 | frame_size = (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) + |
| 357 | INCREMENTAL_BUFFER_SIZE; |
| 358 | |
| 359 | priv->rx_buffer_size = frame_size; |
| 360 | } |
| 361 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 362 | static void gfar_mac_rx_config(struct gfar_private *priv) |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 363 | { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 364 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 365 | u32 rctrl = 0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 366 | |
Sandeep Gopalpet | 1ccb838 | 2009-12-16 01:14:58 +0000 | [diff] [blame] | 367 | if (priv->rx_filer_enable) { |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 368 | rctrl |= RCTRL_FILREN; |
Sandeep Gopalpet | 1ccb838 | 2009-12-16 01:14:58 +0000 | [diff] [blame] | 369 | /* Program the RIR0 reg with the required distribution */ |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 370 | if (priv->poll_mode == GFAR_SQ_POLLING) |
| 371 | gfar_write(®s->rir0, DEFAULT_2RXQ_RIR0); |
| 372 | else /* GFAR_MQ_POLLING */ |
| 373 | gfar_write(®s->rir0, DEFAULT_8RXQ_RIR0); |
Sandeep Gopalpet | 1ccb838 | 2009-12-16 01:14:58 +0000 | [diff] [blame] | 374 | } |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 375 | |
Claudiu Manoil | f5ae627 | 2013-01-23 00:18:36 +0000 | [diff] [blame] | 376 | /* Restore PROMISC mode */ |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 377 | if (priv->ndev->flags & IFF_PROMISC) |
Claudiu Manoil | f5ae627 | 2013-01-23 00:18:36 +0000 | [diff] [blame] | 378 | rctrl |= RCTRL_PROM; |
| 379 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 380 | if (priv->ndev->features & NETIF_F_RXCSUM) |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 381 | rctrl |= RCTRL_CHECKSUMMING; |
| 382 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 383 | if (priv->extended_hash) |
| 384 | rctrl |= RCTRL_EXTHASH | RCTRL_EMEN; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 385 | |
| 386 | if (priv->padding) { |
| 387 | rctrl &= ~RCTRL_PAL_MASK; |
| 388 | rctrl |= RCTRL_PADDING(priv->padding); |
| 389 | } |
| 390 | |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 391 | /* Enable HW time stamping if requested from user space */ |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 392 | if (priv->hwts_rx_en) |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 393 | rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE; |
| 394 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 395 | if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Sebastian Pöhn | b852b72 | 2011-07-26 00:03:13 +0000 | [diff] [blame] | 396 | rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT; |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 397 | |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 398 | /* Clear the LFC bit */ |
| 399 | gfar_write(®s->rctrl, rctrl); |
| 400 | /* Init flow control threshold values */ |
| 401 | gfar_init_rqprm(priv); |
| 402 | gfar_write(®s->ptv, DEFAULT_LFC_PTVVAL); |
| 403 | rctrl |= RCTRL_LFC; |
| 404 | |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 405 | /* Init rctrl based on our settings */ |
| 406 | gfar_write(®s->rctrl, rctrl); |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 407 | } |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 408 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 409 | static void gfar_mac_tx_config(struct gfar_private *priv) |
| 410 | { |
| 411 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
| 412 | u32 tctrl = 0; |
| 413 | |
| 414 | if (priv->ndev->features & NETIF_F_IP_CSUM) |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 415 | tctrl |= TCTRL_INIT_CSUM; |
| 416 | |
Claudiu Manoil | b98b8ba | 2012-09-23 22:39:08 +0000 | [diff] [blame] | 417 | if (priv->prio_sched_en) |
| 418 | tctrl |= TCTRL_TXSCHED_PRIO; |
| 419 | else { |
| 420 | tctrl |= TCTRL_TXSCHED_WRRS; |
| 421 | gfar_write(®s->tr03wt, DEFAULT_WRRS_WEIGHT); |
| 422 | gfar_write(®s->tr47wt, DEFAULT_WRRS_WEIGHT); |
| 423 | } |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 424 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 425 | if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_TX) |
| 426 | tctrl |= TCTRL_VLINS; |
| 427 | |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 428 | gfar_write(®s->tctrl, tctrl); |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Claudiu Manoil | f19015b | 2014-02-24 12:13:46 +0200 | [diff] [blame] | 431 | static void gfar_configure_coalescing(struct gfar_private *priv, |
| 432 | unsigned long tx_mask, unsigned long rx_mask) |
| 433 | { |
| 434 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
| 435 | u32 __iomem *baddr; |
| 436 | |
| 437 | if (priv->mode == MQ_MG_MODE) { |
| 438 | int i = 0; |
| 439 | |
| 440 | baddr = ®s->txic0; |
| 441 | for_each_set_bit(i, &tx_mask, priv->num_tx_queues) { |
| 442 | gfar_write(baddr + i, 0); |
| 443 | if (likely(priv->tx_queue[i]->txcoalescing)) |
| 444 | gfar_write(baddr + i, priv->tx_queue[i]->txic); |
| 445 | } |
| 446 | |
| 447 | baddr = ®s->rxic0; |
| 448 | for_each_set_bit(i, &rx_mask, priv->num_rx_queues) { |
| 449 | gfar_write(baddr + i, 0); |
| 450 | if (likely(priv->rx_queue[i]->rxcoalescing)) |
| 451 | gfar_write(baddr + i, priv->rx_queue[i]->rxic); |
| 452 | } |
| 453 | } else { |
| 454 | /* Backward compatible case -- even if we enable |
| 455 | * multiple queues, there's only single reg to program |
| 456 | */ |
| 457 | gfar_write(®s->txic, 0); |
| 458 | if (likely(priv->tx_queue[0]->txcoalescing)) |
| 459 | gfar_write(®s->txic, priv->tx_queue[0]->txic); |
| 460 | |
| 461 | gfar_write(®s->rxic, 0); |
| 462 | if (unlikely(priv->rx_queue[0]->rxcoalescing)) |
| 463 | gfar_write(®s->rxic, priv->rx_queue[0]->rxic); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | void gfar_configure_coalescing_all(struct gfar_private *priv) |
| 468 | { |
| 469 | gfar_configure_coalescing(priv, 0xFF, 0xFF); |
| 470 | } |
| 471 | |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 472 | static struct net_device_stats *gfar_get_stats(struct net_device *dev) |
| 473 | { |
| 474 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 475 | unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0; |
| 476 | unsigned long tx_packets = 0, tx_bytes = 0; |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 477 | int i; |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 478 | |
| 479 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 480 | rx_packets += priv->rx_queue[i]->stats.rx_packets; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 481 | rx_bytes += priv->rx_queue[i]->stats.rx_bytes; |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 482 | rx_dropped += priv->rx_queue[i]->stats.rx_dropped; |
| 483 | } |
| 484 | |
| 485 | dev->stats.rx_packets = rx_packets; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 486 | dev->stats.rx_bytes = rx_bytes; |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 487 | dev->stats.rx_dropped = rx_dropped; |
| 488 | |
| 489 | for (i = 0; i < priv->num_tx_queues; i++) { |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 490 | tx_bytes += priv->tx_queue[i]->stats.tx_bytes; |
| 491 | tx_packets += priv->tx_queue[i]->stats.tx_packets; |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 494 | dev->stats.tx_bytes = tx_bytes; |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 495 | dev->stats.tx_packets = tx_packets; |
| 496 | |
| 497 | return &dev->stats; |
| 498 | } |
| 499 | |
Claudiu Manoil | 3d23a05 | 2015-05-06 18:07:30 +0300 | [diff] [blame] | 500 | static int gfar_set_mac_addr(struct net_device *dev, void *p) |
| 501 | { |
| 502 | eth_mac_addr(dev, p); |
| 503 | |
| 504 | gfar_set_mac_for_addr(dev, 0, dev->dev_addr); |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Andy Fleming | 26ccfc3 | 2009-03-10 12:58:28 +0000 | [diff] [blame] | 509 | static const struct net_device_ops gfar_netdev_ops = { |
| 510 | .ndo_open = gfar_enet_open, |
| 511 | .ndo_start_xmit = gfar_start_xmit, |
| 512 | .ndo_stop = gfar_close, |
| 513 | .ndo_change_mtu = gfar_change_mtu, |
Michał Mirosław | 8b3afe9 | 2011-04-15 04:50:50 +0000 | [diff] [blame] | 514 | .ndo_set_features = gfar_set_features, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 515 | .ndo_set_rx_mode = gfar_set_multi, |
Andy Fleming | 26ccfc3 | 2009-03-10 12:58:28 +0000 | [diff] [blame] | 516 | .ndo_tx_timeout = gfar_timeout, |
| 517 | .ndo_do_ioctl = gfar_ioctl, |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 518 | .ndo_get_stats = gfar_get_stats, |
Claudiu Manoil | 3d23a05 | 2015-05-06 18:07:30 +0300 | [diff] [blame] | 519 | .ndo_set_mac_address = gfar_set_mac_addr, |
Ben Hutchings | 240c102 | 2009-07-09 17:54:35 +0000 | [diff] [blame] | 520 | .ndo_validate_addr = eth_validate_addr, |
Andy Fleming | 26ccfc3 | 2009-03-10 12:58:28 +0000 | [diff] [blame] | 521 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 522 | .ndo_poll_controller = gfar_netpoll, |
| 523 | #endif |
| 524 | }; |
| 525 | |
Claudiu Manoil | efeddce | 2014-02-17 12:53:17 +0200 | [diff] [blame] | 526 | static void gfar_ints_disable(struct gfar_private *priv) |
| 527 | { |
| 528 | int i; |
| 529 | for (i = 0; i < priv->num_grps; i++) { |
| 530 | struct gfar __iomem *regs = priv->gfargrp[i].regs; |
| 531 | /* Clear IEVENT */ |
| 532 | gfar_write(®s->ievent, IEVENT_INIT_CLEAR); |
| 533 | |
| 534 | /* Initialize IMASK */ |
| 535 | gfar_write(®s->imask, IMASK_INIT_CLEAR); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | static void gfar_ints_enable(struct gfar_private *priv) |
| 540 | { |
| 541 | int i; |
| 542 | for (i = 0; i < priv->num_grps; i++) { |
| 543 | struct gfar __iomem *regs = priv->gfargrp[i].regs; |
| 544 | /* Unmask the interrupts we look for */ |
| 545 | gfar_write(®s->imask, IMASK_DEFAULT); |
| 546 | } |
| 547 | } |
| 548 | |
Kevin Hao | 91c53f76 | 2014-12-24 14:05:44 +0800 | [diff] [blame] | 549 | static void lock_tx_qs(struct gfar_private *priv) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 550 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 551 | int i; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 552 | |
| 553 | for (i = 0; i < priv->num_tx_queues; i++) |
| 554 | spin_lock(&priv->tx_queue[i]->txlock); |
| 555 | } |
| 556 | |
Kevin Hao | 91c53f76 | 2014-12-24 14:05:44 +0800 | [diff] [blame] | 557 | static void unlock_tx_qs(struct gfar_private *priv) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 558 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 559 | int i; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 560 | |
| 561 | for (i = 0; i < priv->num_tx_queues; i++) |
| 562 | spin_unlock(&priv->tx_queue[i]->txlock); |
| 563 | } |
| 564 | |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 565 | static int gfar_alloc_tx_queues(struct gfar_private *priv) |
| 566 | { |
| 567 | int i; |
| 568 | |
| 569 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 570 | priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q), |
| 571 | GFP_KERNEL); |
| 572 | if (!priv->tx_queue[i]) |
| 573 | return -ENOMEM; |
| 574 | |
| 575 | priv->tx_queue[i]->tx_skbuff = NULL; |
| 576 | priv->tx_queue[i]->qindex = i; |
| 577 | priv->tx_queue[i]->dev = priv->ndev; |
| 578 | spin_lock_init(&(priv->tx_queue[i]->txlock)); |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static int gfar_alloc_rx_queues(struct gfar_private *priv) |
| 584 | { |
| 585 | int i; |
| 586 | |
| 587 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 588 | priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q), |
| 589 | GFP_KERNEL); |
| 590 | if (!priv->rx_queue[i]) |
| 591 | return -ENOMEM; |
| 592 | |
| 593 | priv->rx_queue[i]->rx_skbuff = NULL; |
| 594 | priv->rx_queue[i]->qindex = i; |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 595 | priv->rx_queue[i]->ndev = priv->ndev; |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 596 | } |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static void gfar_free_tx_queues(struct gfar_private *priv) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 601 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 602 | int i; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 603 | |
| 604 | for (i = 0; i < priv->num_tx_queues; i++) |
| 605 | kfree(priv->tx_queue[i]); |
| 606 | } |
| 607 | |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 608 | static void gfar_free_rx_queues(struct gfar_private *priv) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 609 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 610 | int i; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 611 | |
| 612 | for (i = 0; i < priv->num_rx_queues; i++) |
| 613 | kfree(priv->rx_queue[i]); |
| 614 | } |
| 615 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 616 | static void unmap_group_regs(struct gfar_private *priv) |
| 617 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 618 | int i; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 619 | |
| 620 | for (i = 0; i < MAXGROUPS; i++) |
| 621 | if (priv->gfargrp[i].regs) |
| 622 | iounmap(priv->gfargrp[i].regs); |
| 623 | } |
| 624 | |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 625 | static void free_gfar_dev(struct gfar_private *priv) |
| 626 | { |
| 627 | int i, j; |
| 628 | |
| 629 | for (i = 0; i < priv->num_grps; i++) |
| 630 | for (j = 0; j < GFAR_NUM_IRQS; j++) { |
| 631 | kfree(priv->gfargrp[i].irqinfo[j]); |
| 632 | priv->gfargrp[i].irqinfo[j] = NULL; |
| 633 | } |
| 634 | |
| 635 | free_netdev(priv->ndev); |
| 636 | } |
| 637 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 638 | static void disable_napi(struct gfar_private *priv) |
| 639 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 640 | int i; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 641 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 642 | for (i = 0; i < priv->num_grps; i++) { |
| 643 | napi_disable(&priv->gfargrp[i].napi_rx); |
| 644 | napi_disable(&priv->gfargrp[i].napi_tx); |
| 645 | } |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static void enable_napi(struct gfar_private *priv) |
| 649 | { |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 650 | int i; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 651 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 652 | for (i = 0; i < priv->num_grps; i++) { |
| 653 | napi_enable(&priv->gfargrp[i].napi_rx); |
| 654 | napi_enable(&priv->gfargrp[i].napi_tx); |
| 655 | } |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | static int gfar_parse_group(struct device_node *np, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 659 | struct gfar_private *priv, const char *model) |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 660 | { |
Claudiu Manoil | 5fedcc1 | 2013-01-29 03:55:11 +0000 | [diff] [blame] | 661 | struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps]; |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 662 | int i; |
| 663 | |
Paul Gortmaker | 7c1e7e9 | 2013-02-04 09:49:42 +0000 | [diff] [blame] | 664 | for (i = 0; i < GFAR_NUM_IRQS; i++) { |
| 665 | grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo), |
| 666 | GFP_KERNEL); |
| 667 | if (!grp->irqinfo[i]) |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 668 | return -ENOMEM; |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 669 | } |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 670 | |
Claudiu Manoil | 5fedcc1 | 2013-01-29 03:55:11 +0000 | [diff] [blame] | 671 | grp->regs = of_iomap(np, 0); |
| 672 | if (!grp->regs) |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 673 | return -ENOMEM; |
| 674 | |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 675 | gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 676 | |
| 677 | /* If we aren't the FEC we have multiple interrupts */ |
| 678 | if (model && strcasecmp(model, "FEC")) { |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 679 | gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1); |
| 680 | gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2); |
| 681 | if (gfar_irq(grp, TX)->irq == NO_IRQ || |
| 682 | gfar_irq(grp, RX)->irq == NO_IRQ || |
| 683 | gfar_irq(grp, ER)->irq == NO_IRQ) |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 684 | return -EINVAL; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Claudiu Manoil | 5fedcc1 | 2013-01-29 03:55:11 +0000 | [diff] [blame] | 687 | grp->priv = priv; |
| 688 | spin_lock_init(&grp->grplock); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 689 | if (priv->mode == MQ_MG_MODE) { |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 690 | u32 rxq_mask, txq_mask; |
| 691 | int ret; |
| 692 | |
| 693 | grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
| 694 | grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
| 695 | |
| 696 | ret = of_property_read_u32(np, "fsl,rx-bit-map", &rxq_mask); |
| 697 | if (!ret) { |
| 698 | grp->rx_bit_map = rxq_mask ? |
| 699 | rxq_mask : (DEFAULT_MAPPING >> priv->num_grps); |
| 700 | } |
| 701 | |
| 702 | ret = of_property_read_u32(np, "fsl,tx-bit-map", &txq_mask); |
| 703 | if (!ret) { |
| 704 | grp->tx_bit_map = txq_mask ? |
| 705 | txq_mask : (DEFAULT_MAPPING >> priv->num_grps); |
| 706 | } |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 707 | |
| 708 | if (priv->poll_mode == GFAR_SQ_POLLING) { |
| 709 | /* One Q per interrupt group: Q0 to G0, Q1 to G1 */ |
| 710 | grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
| 711 | grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps); |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 712 | } |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 713 | } else { |
Claudiu Manoil | 5fedcc1 | 2013-01-29 03:55:11 +0000 | [diff] [blame] | 714 | grp->rx_bit_map = 0xFF; |
| 715 | grp->tx_bit_map = 0xFF; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 716 | } |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 717 | |
| 718 | /* bit_map's MSB is q0 (from q0 to q7) but, for_each_set_bit parses |
| 719 | * right to left, so we need to revert the 8 bits to get the q index |
| 720 | */ |
| 721 | grp->rx_bit_map = bitrev8(grp->rx_bit_map); |
| 722 | grp->tx_bit_map = bitrev8(grp->tx_bit_map); |
| 723 | |
| 724 | /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values, |
| 725 | * also assign queues to groups |
| 726 | */ |
| 727 | for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) { |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 728 | if (!grp->rx_queue) |
| 729 | grp->rx_queue = priv->rx_queue[i]; |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 730 | grp->num_rx_queues++; |
| 731 | grp->rstat |= (RSTAT_CLEAR_RHALT >> i); |
| 732 | priv->rqueue |= ((RQUEUE_EN0 | RQUEUE_EX0) >> i); |
| 733 | priv->rx_queue[i]->grp = grp; |
| 734 | } |
| 735 | |
| 736 | for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) { |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 737 | if (!grp->tx_queue) |
| 738 | grp->tx_queue = priv->tx_queue[i]; |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 739 | grp->num_tx_queues++; |
| 740 | grp->tstat |= (TSTAT_CLEAR_THALT >> i); |
| 741 | priv->tqueue |= (TQUEUE_EN0 >> i); |
| 742 | priv->tx_queue[i]->grp = grp; |
| 743 | } |
| 744 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 745 | priv->num_grps++; |
| 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
Tobias Waldekranz | f50724c | 2015-03-05 14:48:23 +0100 | [diff] [blame] | 750 | static int gfar_of_group_count(struct device_node *np) |
| 751 | { |
| 752 | struct device_node *child; |
| 753 | int num = 0; |
| 754 | |
| 755 | for_each_available_child_of_node(np, child) |
| 756 | if (!of_node_cmp(child->name, "queue-group")) |
| 757 | num++; |
| 758 | |
| 759 | return num; |
| 760 | } |
| 761 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 762 | static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 763 | { |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 764 | const char *model; |
| 765 | const char *ctype; |
| 766 | const void *mac_addr; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 767 | int err = 0, i; |
| 768 | struct net_device *dev = NULL; |
| 769 | struct gfar_private *priv = NULL; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 770 | struct device_node *np = ofdev->dev.of_node; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 771 | struct device_node *child = NULL; |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 772 | struct property *stash; |
| 773 | u32 stash_len = 0; |
| 774 | u32 stash_idx = 0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 775 | unsigned int num_tx_qs, num_rx_qs; |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 776 | unsigned short mode, poll_mode; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 777 | |
Kevin Hao | 4b222ca | 2015-01-28 20:06:48 +0800 | [diff] [blame] | 778 | if (!np) |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 779 | return -ENODEV; |
| 780 | |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 781 | if (of_device_is_compatible(np, "fsl,etsec2")) { |
| 782 | mode = MQ_MG_MODE; |
| 783 | poll_mode = GFAR_SQ_POLLING; |
| 784 | } else { |
| 785 | mode = SQ_SG_MODE; |
| 786 | poll_mode = GFAR_SQ_POLLING; |
| 787 | } |
| 788 | |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 789 | if (mode == SQ_SG_MODE) { |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 790 | num_tx_qs = 1; |
| 791 | num_rx_qs = 1; |
| 792 | } else { /* MQ_MG_MODE */ |
Claudiu Manoil | c65d753 | 2014-03-21 09:33:17 +0200 | [diff] [blame] | 793 | /* get the actual number of supported groups */ |
Tobias Waldekranz | f50724c | 2015-03-05 14:48:23 +0100 | [diff] [blame] | 794 | unsigned int num_grps = gfar_of_group_count(np); |
Claudiu Manoil | c65d753 | 2014-03-21 09:33:17 +0200 | [diff] [blame] | 795 | |
| 796 | if (num_grps == 0 || num_grps > MAXGROUPS) { |
| 797 | dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n", |
| 798 | num_grps); |
| 799 | pr_err("Cannot do alloc_etherdev, aborting\n"); |
| 800 | return -EINVAL; |
| 801 | } |
| 802 | |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 803 | if (poll_mode == GFAR_SQ_POLLING) { |
Claudiu Manoil | c65d753 | 2014-03-21 09:33:17 +0200 | [diff] [blame] | 804 | num_tx_qs = num_grps; /* one txq per int group */ |
| 805 | num_rx_qs = num_grps; /* one rxq per int group */ |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 806 | } else { /* GFAR_MQ_POLLING */ |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 807 | u32 tx_queues, rx_queues; |
| 808 | int ret; |
| 809 | |
| 810 | /* parse the num of HW tx and rx queues */ |
| 811 | ret = of_property_read_u32(np, "fsl,num_tx_queues", |
| 812 | &tx_queues); |
| 813 | num_tx_qs = ret ? 1 : tx_queues; |
| 814 | |
| 815 | ret = of_property_read_u32(np, "fsl,num_rx_queues", |
| 816 | &rx_queues); |
| 817 | num_rx_qs = ret ? 1 : rx_queues; |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 818 | } |
| 819 | } |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 820 | |
| 821 | if (num_tx_qs > MAX_TX_QS) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 822 | pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n", |
| 823 | num_tx_qs, MAX_TX_QS); |
| 824 | pr_err("Cannot do alloc_etherdev, aborting\n"); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 825 | return -EINVAL; |
| 826 | } |
| 827 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 828 | if (num_rx_qs > MAX_RX_QS) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 829 | pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n", |
| 830 | num_rx_qs, MAX_RX_QS); |
| 831 | pr_err("Cannot do alloc_etherdev, aborting\n"); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 832 | return -EINVAL; |
| 833 | } |
| 834 | |
| 835 | *pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs); |
| 836 | dev = *pdev; |
| 837 | if (NULL == dev) |
| 838 | return -ENOMEM; |
| 839 | |
| 840 | priv = netdev_priv(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 841 | priv->ndev = dev; |
| 842 | |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 843 | priv->mode = mode; |
| 844 | priv->poll_mode = poll_mode; |
| 845 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 846 | priv->num_tx_queues = num_tx_qs; |
Ben Hutchings | fe06912 | 2010-09-27 08:27:37 +0000 | [diff] [blame] | 847 | netif_set_real_num_rx_queues(dev, num_rx_qs); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 848 | priv->num_rx_queues = num_rx_qs; |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 849 | |
| 850 | err = gfar_alloc_tx_queues(priv); |
| 851 | if (err) |
| 852 | goto tx_alloc_failed; |
| 853 | |
| 854 | err = gfar_alloc_rx_queues(priv); |
| 855 | if (err) |
| 856 | goto rx_alloc_failed; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 857 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 858 | err = of_property_read_string(np, "model", &model); |
| 859 | if (err) { |
| 860 | pr_err("Device model property missing, aborting\n"); |
| 861 | goto rx_alloc_failed; |
| 862 | } |
| 863 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 864 | /* Init Rx queue filer rule set linked list */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 865 | INIT_LIST_HEAD(&priv->rx_list.list); |
| 866 | priv->rx_list.count = 0; |
| 867 | mutex_init(&priv->rx_queue_access); |
| 868 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 869 | for (i = 0; i < MAXGROUPS; i++) |
| 870 | priv->gfargrp[i].regs = NULL; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 871 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 872 | /* Parse and initialize group specific information */ |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 873 | if (priv->mode == MQ_MG_MODE) { |
Tobias Waldekranz | f50724c | 2015-03-05 14:48:23 +0100 | [diff] [blame] | 874 | for_each_available_child_of_node(np, child) { |
| 875 | if (of_node_cmp(child->name, "queue-group")) |
| 876 | continue; |
| 877 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 878 | err = gfar_parse_group(child, priv, model); |
| 879 | if (err) |
| 880 | goto err_grp_init; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 881 | } |
Claudiu Manoil | b338ce2 | 2014-03-11 18:01:24 +0200 | [diff] [blame] | 882 | } else { /* SQ_SG_MODE */ |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 883 | err = gfar_parse_group(np, priv, model); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 884 | if (err) |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 885 | goto err_grp_init; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 888 | stash = of_find_property(np, "bd-stash", NULL); |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 889 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 890 | if (stash) { |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 891 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING; |
| 892 | priv->bd_stash_en = 1; |
| 893 | } |
| 894 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 895 | err = of_property_read_u32(np, "rx-stash-len", &stash_len); |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 896 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 897 | if (err == 0) |
| 898 | priv->rx_stash_size = stash_len; |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 899 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 900 | err = of_property_read_u32(np, "rx-stash-idx", &stash_idx); |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 901 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 902 | if (err == 0) |
| 903 | priv->rx_stash_index = stash_idx; |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 904 | |
| 905 | if (stash_len || stash_idx) |
| 906 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING; |
| 907 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 908 | mac_addr = of_get_mac_address(np); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 909 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 910 | if (mac_addr) |
Joe Perches | 6a3c910c | 2011-11-16 09:38:02 +0000 | [diff] [blame] | 911 | memcpy(dev->dev_addr, mac_addr, ETH_ALEN); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 912 | |
| 913 | if (model && !strcasecmp(model, "TSEC")) |
Claudiu Manoil | 34018fd | 2014-02-17 12:53:15 +0200 | [diff] [blame] | 914 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 915 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 916 | FSL_GIANFAR_DEV_HAS_RMON | |
| 917 | FSL_GIANFAR_DEV_HAS_MULTI_INTR; |
| 918 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 919 | if (model && !strcasecmp(model, "eTSEC")) |
Claudiu Manoil | 34018fd | 2014-02-17 12:53:15 +0200 | [diff] [blame] | 920 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 921 | FSL_GIANFAR_DEV_HAS_COALESCE | |
| 922 | FSL_GIANFAR_DEV_HAS_RMON | |
| 923 | FSL_GIANFAR_DEV_HAS_MULTI_INTR | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 924 | FSL_GIANFAR_DEV_HAS_CSUM | |
| 925 | FSL_GIANFAR_DEV_HAS_VLAN | |
| 926 | FSL_GIANFAR_DEV_HAS_MAGIC_PACKET | |
| 927 | FSL_GIANFAR_DEV_HAS_EXTENDED_HASH | |
| 928 | FSL_GIANFAR_DEV_HAS_TIMER; |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 929 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 930 | err = of_property_read_string(np, "phy-connection-type", &ctype); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 931 | |
| 932 | /* We only care about rgmii-id. The rest are autodetected */ |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 933 | if (err == 0 && !strcmp(ctype, "rgmii-id")) |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 934 | priv->interface = PHY_INTERFACE_MODE_RGMII_ID; |
| 935 | else |
| 936 | priv->interface = PHY_INTERFACE_MODE_MII; |
| 937 | |
Jingchang Lu | 5591764 | 2015-03-13 10:52:32 +0200 | [diff] [blame] | 938 | if (of_find_property(np, "fsl,magic-packet", NULL)) |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 939 | priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET; |
| 940 | |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 941 | priv->phy_node = of_parse_phandle(np, "phy-handle", 0); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 942 | |
Florian Fainelli | be40364 | 2014-05-22 09:47:48 -0700 | [diff] [blame] | 943 | /* In the case of a fixed PHY, the DT node associated |
| 944 | * to the PHY is the Ethernet MAC DT node. |
| 945 | */ |
Uwe Kleine-König | 6f2c9bd | 2014-08-07 22:17:07 +0200 | [diff] [blame] | 946 | if (!priv->phy_node && of_phy_is_fixed_link(np)) { |
Florian Fainelli | be40364 | 2014-05-22 09:47:48 -0700 | [diff] [blame] | 947 | err = of_phy_register_fixed_link(np); |
| 948 | if (err) |
| 949 | goto err_grp_init; |
| 950 | |
Uwe Kleine-König | 6f2c9bd | 2014-08-07 22:17:07 +0200 | [diff] [blame] | 951 | priv->phy_node = of_node_get(np); |
Florian Fainelli | be40364 | 2014-05-22 09:47:48 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 954 | /* Find the TBI PHY. If it's not there, we don't support SGMII */ |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 955 | priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 956 | |
| 957 | return 0; |
| 958 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 959 | err_grp_init: |
| 960 | unmap_group_regs(priv); |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 961 | rx_alloc_failed: |
| 962 | gfar_free_rx_queues(priv); |
| 963 | tx_alloc_failed: |
| 964 | gfar_free_tx_queues(priv); |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 965 | free_gfar_dev(priv); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 966 | return err; |
| 967 | } |
| 968 | |
Ben Hutchings | ca0c88c | 2013-11-18 23:05:27 +0000 | [diff] [blame] | 969 | static int gfar_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr) |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 970 | { |
| 971 | struct hwtstamp_config config; |
| 972 | struct gfar_private *priv = netdev_priv(netdev); |
| 973 | |
| 974 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 975 | return -EFAULT; |
| 976 | |
| 977 | /* reserved for future extensions */ |
| 978 | if (config.flags) |
| 979 | return -EINVAL; |
| 980 | |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 981 | switch (config.tx_type) { |
| 982 | case HWTSTAMP_TX_OFF: |
| 983 | priv->hwts_tx_en = 0; |
| 984 | break; |
| 985 | case HWTSTAMP_TX_ON: |
| 986 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) |
| 987 | return -ERANGE; |
| 988 | priv->hwts_tx_en = 1; |
| 989 | break; |
| 990 | default: |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 991 | return -ERANGE; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 992 | } |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 993 | |
| 994 | switch (config.rx_filter) { |
| 995 | case HWTSTAMP_FILTER_NONE: |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 996 | if (priv->hwts_rx_en) { |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 997 | priv->hwts_rx_en = 0; |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 998 | reset_gfar(netdev); |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 999 | } |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 1000 | break; |
| 1001 | default: |
| 1002 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) |
| 1003 | return -ERANGE; |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 1004 | if (!priv->hwts_rx_en) { |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 1005 | priv->hwts_rx_en = 1; |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1006 | reset_gfar(netdev); |
Manfred Rudigier | 97553f7 | 2010-06-11 01:49:05 +0000 | [diff] [blame] | 1007 | } |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 1008 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 1013 | -EFAULT : 0; |
| 1014 | } |
| 1015 | |
Ben Hutchings | ca0c88c | 2013-11-18 23:05:27 +0000 | [diff] [blame] | 1016 | static int gfar_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr) |
| 1017 | { |
| 1018 | struct hwtstamp_config config; |
| 1019 | struct gfar_private *priv = netdev_priv(netdev); |
| 1020 | |
| 1021 | config.flags = 0; |
| 1022 | config.tx_type = priv->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; |
| 1023 | config.rx_filter = (priv->hwts_rx_en ? |
| 1024 | HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE); |
| 1025 | |
| 1026 | return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 1027 | -EFAULT : 0; |
| 1028 | } |
| 1029 | |
Clifford Wolf | 0faac9f | 2009-01-09 10:23:11 +0000 | [diff] [blame] | 1030 | static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1031 | { |
| 1032 | struct gfar_private *priv = netdev_priv(dev); |
| 1033 | |
| 1034 | if (!netif_running(dev)) |
| 1035 | return -EINVAL; |
| 1036 | |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 1037 | if (cmd == SIOCSHWTSTAMP) |
Ben Hutchings | ca0c88c | 2013-11-18 23:05:27 +0000 | [diff] [blame] | 1038 | return gfar_hwtstamp_set(dev, rq); |
| 1039 | if (cmd == SIOCGHWTSTAMP) |
| 1040 | return gfar_hwtstamp_get(dev, rq); |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 1041 | |
Clifford Wolf | 0faac9f | 2009-01-09 10:23:11 +0000 | [diff] [blame] | 1042 | if (!priv->phydev) |
| 1043 | return -ENODEV; |
| 1044 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 1045 | return phy_mii_ioctl(priv->phydev, rq, cmd); |
Clifford Wolf | 0faac9f | 2009-01-09 10:23:11 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Anton Vorontsov | 18294ad | 2009-11-04 12:53:00 +0000 | [diff] [blame] | 1048 | static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar, |
| 1049 | u32 class) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1050 | { |
| 1051 | u32 rqfpr = FPR_FILER_MASK; |
| 1052 | u32 rqfcr = 0x0; |
| 1053 | |
| 1054 | rqfar--; |
| 1055 | rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1056 | priv->ftp_rqfpr[rqfar] = rqfpr; |
| 1057 | priv->ftp_rqfcr[rqfar] = rqfcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1058 | gfar_write_filer(priv, rqfar, rqfcr, rqfpr); |
| 1059 | |
| 1060 | rqfar--; |
| 1061 | rqfcr = RQFCR_CMP_NOMATCH; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1062 | priv->ftp_rqfpr[rqfar] = rqfpr; |
| 1063 | priv->ftp_rqfcr[rqfar] = rqfcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1064 | gfar_write_filer(priv, rqfar, rqfcr, rqfpr); |
| 1065 | |
| 1066 | rqfar--; |
| 1067 | rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND; |
| 1068 | rqfpr = class; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1069 | priv->ftp_rqfcr[rqfar] = rqfcr; |
| 1070 | priv->ftp_rqfpr[rqfar] = rqfpr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1071 | gfar_write_filer(priv, rqfar, rqfcr, rqfpr); |
| 1072 | |
| 1073 | rqfar--; |
| 1074 | rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND; |
| 1075 | rqfpr = class; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1076 | priv->ftp_rqfcr[rqfar] = rqfcr; |
| 1077 | priv->ftp_rqfpr[rqfar] = rqfpr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1078 | gfar_write_filer(priv, rqfar, rqfcr, rqfpr); |
| 1079 | |
| 1080 | return rqfar; |
| 1081 | } |
| 1082 | |
| 1083 | static void gfar_init_filer_table(struct gfar_private *priv) |
| 1084 | { |
| 1085 | int i = 0x0; |
| 1086 | u32 rqfar = MAX_FILER_IDX; |
| 1087 | u32 rqfcr = 0x0; |
| 1088 | u32 rqfpr = FPR_FILER_MASK; |
| 1089 | |
| 1090 | /* Default rule */ |
| 1091 | rqfcr = RQFCR_CMP_MATCH; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1092 | priv->ftp_rqfcr[rqfar] = rqfcr; |
| 1093 | priv->ftp_rqfpr[rqfar] = rqfpr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1094 | gfar_write_filer(priv, rqfar, rqfcr, rqfpr); |
| 1095 | |
| 1096 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6); |
| 1097 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP); |
| 1098 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP); |
| 1099 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4); |
| 1100 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP); |
| 1101 | rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP); |
| 1102 | |
Uwe Kleine-König | 85dd08e | 2010-06-11 12:16:55 +0200 | [diff] [blame] | 1103 | /* cur_filer_idx indicated the first non-masked rule */ |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1104 | priv->cur_filer_idx = rqfar; |
| 1105 | |
| 1106 | /* Rest are masked rules */ |
| 1107 | rqfcr = RQFCR_CMP_NOMATCH; |
| 1108 | for (i = 0; i < rqfar; i++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 1109 | priv->ftp_rqfcr[i] = rqfcr; |
| 1110 | priv->ftp_rqfpr[i] = rqfpr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1111 | gfar_write_filer(priv, i, rqfcr, rqfpr); |
| 1112 | } |
| 1113 | } |
| 1114 | |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 1115 | #ifdef CONFIG_PPC |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1116 | static void __gfar_detect_errata_83xx(struct gfar_private *priv) |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1117 | { |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1118 | unsigned int pvr = mfspr(SPRN_PVR); |
| 1119 | unsigned int svr = mfspr(SPRN_SVR); |
| 1120 | unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */ |
| 1121 | unsigned int rev = svr & 0xffff; |
| 1122 | |
| 1123 | /* MPC8313 Rev 2.0 and higher; All MPC837x */ |
| 1124 | if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) || |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1125 | (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1126 | priv->errata |= GFAR_ERRATA_74; |
| 1127 | |
Anton Vorontsov | deb90ea | 2010-06-30 06:39:13 +0000 | [diff] [blame] | 1128 | /* MPC8313 and MPC837x all rev */ |
| 1129 | if ((pvr == 0x80850010 && mod == 0x80b0) || |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1130 | (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) |
Anton Vorontsov | deb90ea | 2010-06-30 06:39:13 +0000 | [diff] [blame] | 1131 | priv->errata |= GFAR_ERRATA_76; |
| 1132 | |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1133 | /* MPC8313 Rev < 2.0 */ |
| 1134 | if (pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020) |
Alex Dubov | 4363c2fdd | 2011-03-16 17:57:13 +0000 | [diff] [blame] | 1135 | priv->errata |= GFAR_ERRATA_12; |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | static void __gfar_detect_errata_85xx(struct gfar_private *priv) |
| 1139 | { |
| 1140 | unsigned int svr = mfspr(SPRN_SVR); |
| 1141 | |
| 1142 | if ((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) == 0x20)) |
| 1143 | priv->errata |= GFAR_ERRATA_12; |
Claudiu Manoil | 53fad77 | 2013-10-09 20:20:42 +0300 | [diff] [blame] | 1144 | if (((SVR_SOC_VER(svr) == SVR_P2020) && (SVR_REV(svr) < 0x20)) || |
| 1145 | ((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20))) |
| 1146 | priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */ |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1147 | } |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 1148 | #endif |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1149 | |
| 1150 | static void gfar_detect_errata(struct gfar_private *priv) |
| 1151 | { |
| 1152 | struct device *dev = &priv->ofdev->dev; |
| 1153 | |
| 1154 | /* no plans to fix */ |
| 1155 | priv->errata |= GFAR_ERRATA_A002; |
| 1156 | |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 1157 | #ifdef CONFIG_PPC |
Claudiu Manoil | 2969b1f | 2013-10-09 20:20:41 +0300 | [diff] [blame] | 1158 | if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2)) |
| 1159 | __gfar_detect_errata_85xx(priv); |
| 1160 | else /* non-mpc85xx parts, i.e. e300 core based */ |
| 1161 | __gfar_detect_errata_83xx(priv); |
Claudiu Manoil | d6ef0bc | 2014-10-07 10:44:32 +0300 | [diff] [blame] | 1162 | #endif |
Alex Dubov | 4363c2fdd | 2011-03-16 17:57:13 +0000 | [diff] [blame] | 1163 | |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1164 | if (priv->errata) |
| 1165 | dev_info(dev, "enabled errata workarounds, flags: 0x%x\n", |
| 1166 | priv->errata); |
| 1167 | } |
| 1168 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1169 | void gfar_mac_reset(struct gfar_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | { |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1171 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1172 | u32 tempval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
| 1174 | /* Reset MAC layer */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1175 | gfar_write(®s->maccfg1, MACCFG1_SOFT_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
Andy Fleming | b98ac70 | 2009-02-04 16:38:05 -0800 | [diff] [blame] | 1177 | /* We need to delay at least 3 TX clocks */ |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1178 | udelay(3); |
Andy Fleming | b98ac70 | 2009-02-04 16:38:05 -0800 | [diff] [blame] | 1179 | |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 1180 | /* the soft reset bit is not self-resetting, so we need to |
| 1181 | * clear it before resuming normal operation |
| 1182 | */ |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1183 | gfar_write(®s->maccfg1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1185 | udelay(3); |
| 1186 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 1187 | /* Compute rx_buff_size based on config flags */ |
| 1188 | gfar_rx_buff_size_config(priv); |
| 1189 | |
| 1190 | /* Initialize the max receive frame/buffer lengths */ |
| 1191 | gfar_write(®s->maxfrm, priv->rx_buffer_size); |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1192 | gfar_write(®s->mrblr, priv->rx_buffer_size); |
| 1193 | |
| 1194 | /* Initialize the Minimum Frame Length Register */ |
| 1195 | gfar_write(®s->minflr, MINFLR_INIT_SETTINGS); |
| 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | /* Initialize MACCFG2. */ |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1198 | tempval = MACCFG2_INIT_SETTINGS; |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 1199 | |
| 1200 | /* If the mtu is larger than the max size for standard |
| 1201 | * ethernet frames (ie, a jumbo frame), then set maccfg2 |
| 1202 | * to allow huge frames, and to check the length |
| 1203 | */ |
| 1204 | if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE || |
| 1205 | gfar_has_errata(priv, GFAR_ERRATA_74)) |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1206 | tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK; |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 1207 | |
Anton Vorontsov | 7d35097 | 2010-06-30 06:39:12 +0000 | [diff] [blame] | 1208 | gfar_write(®s->maccfg2, tempval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1210 | /* Clear mac addr hash registers */ |
| 1211 | gfar_write(®s->igaddr0, 0); |
| 1212 | gfar_write(®s->igaddr1, 0); |
| 1213 | gfar_write(®s->igaddr2, 0); |
| 1214 | gfar_write(®s->igaddr3, 0); |
| 1215 | gfar_write(®s->igaddr4, 0); |
| 1216 | gfar_write(®s->igaddr5, 0); |
| 1217 | gfar_write(®s->igaddr6, 0); |
| 1218 | gfar_write(®s->igaddr7, 0); |
| 1219 | |
| 1220 | gfar_write(®s->gaddr0, 0); |
| 1221 | gfar_write(®s->gaddr1, 0); |
| 1222 | gfar_write(®s->gaddr2, 0); |
| 1223 | gfar_write(®s->gaddr3, 0); |
| 1224 | gfar_write(®s->gaddr4, 0); |
| 1225 | gfar_write(®s->gaddr5, 0); |
| 1226 | gfar_write(®s->gaddr6, 0); |
| 1227 | gfar_write(®s->gaddr7, 0); |
| 1228 | |
| 1229 | if (priv->extended_hash) |
| 1230 | gfar_clear_exact_match(priv->ndev); |
| 1231 | |
| 1232 | gfar_mac_rx_config(priv); |
| 1233 | |
| 1234 | gfar_mac_tx_config(priv); |
| 1235 | |
| 1236 | gfar_set_mac_address(priv->ndev); |
| 1237 | |
| 1238 | gfar_set_multi(priv->ndev); |
| 1239 | |
| 1240 | /* clear ievent and imask before configuring coalescing */ |
| 1241 | gfar_ints_disable(priv); |
| 1242 | |
| 1243 | /* Configure the coalescing support */ |
| 1244 | gfar_configure_coalescing_all(priv); |
| 1245 | } |
| 1246 | |
| 1247 | static void gfar_hw_init(struct gfar_private *priv) |
| 1248 | { |
| 1249 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
| 1250 | u32 attrs; |
| 1251 | |
| 1252 | /* Stop the DMA engine now, in case it was running before |
| 1253 | * (The firmware could have used it, and left it running). |
| 1254 | */ |
| 1255 | gfar_halt(priv); |
| 1256 | |
| 1257 | gfar_mac_reset(priv); |
| 1258 | |
| 1259 | /* Zero out the rmon mib registers if it has them */ |
| 1260 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { |
| 1261 | memset_io(&(regs->rmon), 0, sizeof(struct rmon_mib)); |
| 1262 | |
| 1263 | /* Mask off the CAM interrupts */ |
| 1264 | gfar_write(®s->rmon.cam1, 0xffffffff); |
| 1265 | gfar_write(®s->rmon.cam2, 0xffffffff); |
| 1266 | } |
| 1267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | /* Initialize ECNTRL */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1269 | gfar_write(®s->ecntrl, ECNTRL_INIT_SETTINGS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Claudiu Manoil | 34018fd | 2014-02-17 12:53:15 +0200 | [diff] [blame] | 1271 | /* Set the extraction length and index */ |
| 1272 | attrs = ATTRELI_EL(priv->rx_stash_size) | |
| 1273 | ATTRELI_EI(priv->rx_stash_index); |
| 1274 | |
| 1275 | gfar_write(®s->attreli, attrs); |
| 1276 | |
| 1277 | /* Start with defaults, and add stashing |
| 1278 | * depending on driver parameters |
| 1279 | */ |
| 1280 | attrs = ATTR_INIT_SETTINGS; |
| 1281 | |
| 1282 | if (priv->bd_stash_en) |
| 1283 | attrs |= ATTR_BDSTASH; |
| 1284 | |
| 1285 | if (priv->rx_stash_size != 0) |
| 1286 | attrs |= ATTR_BUFSTASH; |
| 1287 | |
| 1288 | gfar_write(®s->attr, attrs); |
| 1289 | |
| 1290 | /* FIFO configs */ |
| 1291 | gfar_write(®s->fifo_tx_thr, DEFAULT_FIFO_TX_THR); |
| 1292 | gfar_write(®s->fifo_tx_starve, DEFAULT_FIFO_TX_STARVE); |
| 1293 | gfar_write(®s->fifo_tx_starve_shutoff, DEFAULT_FIFO_TX_STARVE_OFF); |
| 1294 | |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1295 | /* Program the interrupt steering regs, only for MG devices */ |
| 1296 | if (priv->num_grps > 1) |
| 1297 | gfar_write_isrg(priv); |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Xiubo Li | 898157e | 2014-06-04 16:49:16 +0800 | [diff] [blame] | 1300 | static void gfar_init_addr_hash_table(struct gfar_private *priv) |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1301 | { |
| 1302 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1303 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1304 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1305 | priv->extended_hash = 1; |
| 1306 | priv->hash_width = 9; |
| 1307 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1308 | priv->hash_regs[0] = ®s->igaddr0; |
| 1309 | priv->hash_regs[1] = ®s->igaddr1; |
| 1310 | priv->hash_regs[2] = ®s->igaddr2; |
| 1311 | priv->hash_regs[3] = ®s->igaddr3; |
| 1312 | priv->hash_regs[4] = ®s->igaddr4; |
| 1313 | priv->hash_regs[5] = ®s->igaddr5; |
| 1314 | priv->hash_regs[6] = ®s->igaddr6; |
| 1315 | priv->hash_regs[7] = ®s->igaddr7; |
| 1316 | priv->hash_regs[8] = ®s->gaddr0; |
| 1317 | priv->hash_regs[9] = ®s->gaddr1; |
| 1318 | priv->hash_regs[10] = ®s->gaddr2; |
| 1319 | priv->hash_regs[11] = ®s->gaddr3; |
| 1320 | priv->hash_regs[12] = ®s->gaddr4; |
| 1321 | priv->hash_regs[13] = ®s->gaddr5; |
| 1322 | priv->hash_regs[14] = ®s->gaddr6; |
| 1323 | priv->hash_regs[15] = ®s->gaddr7; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1324 | |
| 1325 | } else { |
| 1326 | priv->extended_hash = 0; |
| 1327 | priv->hash_width = 8; |
| 1328 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1329 | priv->hash_regs[0] = ®s->gaddr0; |
| 1330 | priv->hash_regs[1] = ®s->gaddr1; |
| 1331 | priv->hash_regs[2] = ®s->gaddr2; |
| 1332 | priv->hash_regs[3] = ®s->gaddr3; |
| 1333 | priv->hash_regs[4] = ®s->gaddr4; |
| 1334 | priv->hash_regs[5] = ®s->gaddr5; |
| 1335 | priv->hash_regs[6] = ®s->gaddr6; |
| 1336 | priv->hash_regs[7] = ®s->gaddr7; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1337 | } |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | /* Set up the ethernet device structure, private data, |
| 1341 | * and anything else we need before we start |
| 1342 | */ |
| 1343 | static int gfar_probe(struct platform_device *ofdev) |
| 1344 | { |
| 1345 | struct net_device *dev = NULL; |
| 1346 | struct gfar_private *priv = NULL; |
| 1347 | int err = 0, i; |
| 1348 | |
| 1349 | err = gfar_of_init(ofdev, &dev); |
| 1350 | |
| 1351 | if (err) |
| 1352 | return err; |
| 1353 | |
| 1354 | priv = netdev_priv(dev); |
| 1355 | priv->ndev = dev; |
| 1356 | priv->ofdev = ofdev; |
| 1357 | priv->dev = &ofdev->dev; |
| 1358 | SET_NETDEV_DEV(dev, &ofdev->dev); |
| 1359 | |
| 1360 | spin_lock_init(&priv->bflock); |
| 1361 | INIT_WORK(&priv->reset_task, gfar_reset_task); |
| 1362 | |
| 1363 | platform_set_drvdata(ofdev, priv); |
| 1364 | |
| 1365 | gfar_detect_errata(priv); |
| 1366 | |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1367 | /* Set the dev->base_addr to the gfar reg region */ |
| 1368 | dev->base_addr = (unsigned long) priv->gfargrp[0].regs; |
| 1369 | |
| 1370 | /* Fill in the dev structure */ |
| 1371 | dev->watchdog_timeo = TX_TIMEOUT; |
| 1372 | dev->mtu = 1500; |
| 1373 | dev->netdev_ops = &gfar_netdev_ops; |
| 1374 | dev->ethtool_ops = &gfar_ethtool_ops; |
| 1375 | |
| 1376 | /* Register for napi ...We are registering NAPI for each grp */ |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 1377 | for (i = 0; i < priv->num_grps; i++) { |
| 1378 | if (priv->poll_mode == GFAR_SQ_POLLING) { |
| 1379 | netif_napi_add(dev, &priv->gfargrp[i].napi_rx, |
| 1380 | gfar_poll_rx_sq, GFAR_DEV_WEIGHT); |
| 1381 | netif_napi_add(dev, &priv->gfargrp[i].napi_tx, |
| 1382 | gfar_poll_tx_sq, 2); |
| 1383 | } else { |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 1384 | netif_napi_add(dev, &priv->gfargrp[i].napi_rx, |
| 1385 | gfar_poll_rx, GFAR_DEV_WEIGHT); |
| 1386 | netif_napi_add(dev, &priv->gfargrp[i].napi_tx, |
| 1387 | gfar_poll_tx, 2); |
| 1388 | } |
| 1389 | } |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1390 | |
| 1391 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) { |
| 1392 | dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | |
| 1393 | NETIF_F_RXCSUM; |
| 1394 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | |
| 1395 | NETIF_F_RXCSUM | NETIF_F_HIGHDMA; |
| 1396 | } |
| 1397 | |
| 1398 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) { |
| 1399 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 1400 | NETIF_F_HW_VLAN_CTAG_RX; |
| 1401 | dev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
| 1402 | } |
| 1403 | |
Claudiu Manoil | 3d23a05 | 2015-05-06 18:07:30 +0300 | [diff] [blame] | 1404 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
| 1405 | |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1406 | gfar_init_addr_hash_table(priv); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1407 | |
Claudiu Manoil | 532c37b | 2014-02-17 12:53:16 +0200 | [diff] [blame] | 1408 | /* Insert receive time stamps into padding alignment bytes */ |
| 1409 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) |
| 1410 | priv->padding = 8; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1411 | |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 1412 | if (dev->features & NETIF_F_IP_CSUM || |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1413 | priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) |
Wu Jiajun-B06378 | bee9e58 | 2012-05-21 23:00:48 +0000 | [diff] [blame] | 1414 | dev->needed_headroom = GMAC_FCB_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
| 1416 | priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1418 | /* Initializing some of the rx/tx queue level parameters */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1419 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 1420 | priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE; |
| 1421 | priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE; |
| 1422 | priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE; |
| 1423 | priv->tx_queue[i]->txic = DEFAULT_TXIC; |
| 1424 | } |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1425 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1426 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 1427 | priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE; |
| 1428 | priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE; |
| 1429 | priv->rx_queue[i]->rxic = DEFAULT_RXIC; |
| 1430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1432 | /* always enable rx filer */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1433 | priv->rx_filer_enable = 1; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1434 | /* Enable most messages by default */ |
| 1435 | priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1; |
Claudiu Manoil | b98b8ba | 2012-09-23 22:39:08 +0000 | [diff] [blame] | 1436 | /* use pritority h/w tx queue scheduling for single queue devices */ |
| 1437 | if (priv->num_tx_queues == 1) |
| 1438 | priv->prio_sched_en = 1; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1439 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1440 | set_bit(GFAR_DOWN, &priv->state); |
| 1441 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1442 | gfar_hw_init(priv); |
Trent Piepho | d3eab82 | 2008-10-02 11:12:24 +0000 | [diff] [blame] | 1443 | |
Fabio Estevam | d4c642e | 2014-06-03 19:55:38 -0300 | [diff] [blame] | 1444 | /* Carrier starts down, phylib will bring it up */ |
| 1445 | netif_carrier_off(dev); |
| 1446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | err = register_netdev(dev); |
| 1448 | |
| 1449 | if (err) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 1450 | pr_err("%s: Cannot register net device, aborting\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | goto register_fail; |
| 1452 | } |
| 1453 | |
Anton Vorontsov | 2884e5c | 2009-02-01 00:52:34 -0800 | [diff] [blame] | 1454 | device_init_wakeup(&dev->dev, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1455 | priv->device_flags & |
| 1456 | FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); |
Anton Vorontsov | 2884e5c | 2009-02-01 00:52:34 -0800 | [diff] [blame] | 1457 | |
Dai Haruki | c50a5d9 | 2008-12-17 16:51:32 -0800 | [diff] [blame] | 1458 | /* fill out IRQ number and name fields */ |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1459 | for (i = 0; i < priv->num_grps; i++) { |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1460 | struct gfar_priv_grp *grp = &priv->gfargrp[i]; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1461 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1462 | sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s", |
Joe Perches | 0015e55 | 2012-03-25 07:10:07 +0000 | [diff] [blame] | 1463 | dev->name, "_g", '0' + i, "_tx"); |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1464 | sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s", |
Joe Perches | 0015e55 | 2012-03-25 07:10:07 +0000 | [diff] [blame] | 1465 | dev->name, "_g", '0' + i, "_rx"); |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1466 | sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s", |
Joe Perches | 0015e55 | 2012-03-25 07:10:07 +0000 | [diff] [blame] | 1467 | dev->name, "_g", '0' + i, "_er"); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1468 | } else |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1469 | strcpy(gfar_irq(grp, TX)->name, dev->name); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1470 | } |
Dai Haruki | c50a5d9 | 2008-12-17 16:51:32 -0800 | [diff] [blame] | 1471 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1472 | /* Initialize the filer table */ |
| 1473 | gfar_init_filer_table(priv); |
| 1474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | /* Print out the device info */ |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 1476 | netdev_info(dev, "mac: %pM\n", dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1478 | /* Even more device info helps when determining which kernel |
| 1479 | * provided which set of benchmarks. |
| 1480 | */ |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 1481 | netdev_info(dev, "Running with NAPI enabled\n"); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1482 | for (i = 0; i < priv->num_rx_queues; i++) |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 1483 | netdev_info(dev, "RX BD ring size for Q[%d]: %d\n", |
| 1484 | i, priv->rx_queue[i]->rx_ring_size); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1485 | for (i = 0; i < priv->num_tx_queues; i++) |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 1486 | netdev_info(dev, "TX BD ring size for Q[%d]: %d\n", |
| 1487 | i, priv->tx_queue[i]->tx_ring_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | return 0; |
| 1490 | |
| 1491 | register_fail: |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1492 | unmap_group_regs(priv); |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1493 | gfar_free_rx_queues(priv); |
| 1494 | gfar_free_tx_queues(priv); |
Uwe Kleine-König | 888c88b | 2014-08-07 21:20:12 +0200 | [diff] [blame] | 1495 | of_node_put(priv->phy_node); |
| 1496 | of_node_put(priv->tbi_node); |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1497 | free_gfar_dev(priv); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1498 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1501 | static int gfar_remove(struct platform_device *ofdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | { |
Jingoo Han | 8513fbd | 2013-05-23 00:52:31 +0000 | [diff] [blame] | 1503 | struct gfar_private *priv = platform_get_drvdata(ofdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
Uwe Kleine-König | 888c88b | 2014-08-07 21:20:12 +0200 | [diff] [blame] | 1505 | of_node_put(priv->phy_node); |
| 1506 | of_node_put(priv->tbi_node); |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1507 | |
David S. Miller | d9d8e04 | 2009-09-06 01:41:02 -0700 | [diff] [blame] | 1508 | unregister_netdev(priv->ndev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1509 | unmap_group_regs(priv); |
Claudiu Manoil | 2086278 | 2014-02-17 12:53:14 +0200 | [diff] [blame] | 1510 | gfar_free_rx_queues(priv); |
| 1511 | gfar_free_tx_queues(priv); |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 1512 | free_gfar_dev(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1517 | #ifdef CONFIG_PM |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1518 | |
| 1519 | static int gfar_suspend(struct device *dev) |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1520 | { |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1521 | struct gfar_private *priv = dev_get_drvdata(dev); |
| 1522 | struct net_device *ndev = priv->ndev; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1523 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1524 | unsigned long flags; |
| 1525 | u32 tempval; |
| 1526 | |
| 1527 | int magic_packet = priv->wol_en && |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1528 | (priv->device_flags & |
| 1529 | FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1530 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1531 | netif_device_detach(ndev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1532 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1533 | if (netif_running(ndev)) { |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1534 | |
| 1535 | local_irq_save(flags); |
| 1536 | lock_tx_qs(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1537 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1538 | gfar_halt_nodisable(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1539 | |
| 1540 | /* Disable Tx, and Rx if wake-on-LAN is disabled. */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1541 | tempval = gfar_read(®s->maccfg1); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1542 | |
| 1543 | tempval &= ~MACCFG1_TX_EN; |
| 1544 | |
| 1545 | if (!magic_packet) |
| 1546 | tempval &= ~MACCFG1_RX_EN; |
| 1547 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1548 | gfar_write(®s->maccfg1, tempval); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1549 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1550 | unlock_tx_qs(priv); |
| 1551 | local_irq_restore(flags); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1552 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1553 | disable_napi(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1554 | |
| 1555 | if (magic_packet) { |
| 1556 | /* Enable interrupt on Magic Packet */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1557 | gfar_write(®s->imask, IMASK_MAG); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1558 | |
| 1559 | /* Enable Magic Packet mode */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1560 | tempval = gfar_read(®s->maccfg2); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1561 | tempval |= MACCFG2_MPEN; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1562 | gfar_write(®s->maccfg2, tempval); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1563 | } else { |
| 1564 | phy_stop(priv->phydev); |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1571 | static int gfar_resume(struct device *dev) |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1572 | { |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1573 | struct gfar_private *priv = dev_get_drvdata(dev); |
| 1574 | struct net_device *ndev = priv->ndev; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1575 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1576 | unsigned long flags; |
| 1577 | u32 tempval; |
| 1578 | int magic_packet = priv->wol_en && |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1579 | (priv->device_flags & |
| 1580 | FSL_GIANFAR_DEV_HAS_MAGIC_PACKET); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1581 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1582 | if (!netif_running(ndev)) { |
| 1583 | netif_device_attach(ndev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1584 | return 0; |
| 1585 | } |
| 1586 | |
| 1587 | if (!magic_packet && priv->phydev) |
| 1588 | phy_start(priv->phydev); |
| 1589 | |
| 1590 | /* Disable Magic Packet mode, in case something |
| 1591 | * else woke us up. |
| 1592 | */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1593 | local_irq_save(flags); |
| 1594 | lock_tx_qs(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1595 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1596 | tempval = gfar_read(®s->maccfg2); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1597 | tempval &= ~MACCFG2_MPEN; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1598 | gfar_write(®s->maccfg2, tempval); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1599 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1600 | gfar_start(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1601 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1602 | unlock_tx_qs(priv); |
| 1603 | local_irq_restore(flags); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1604 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1605 | netif_device_attach(ndev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1606 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1607 | enable_napi(priv); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1608 | |
| 1609 | return 0; |
| 1610 | } |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1611 | |
| 1612 | static int gfar_restore(struct device *dev) |
| 1613 | { |
| 1614 | struct gfar_private *priv = dev_get_drvdata(dev); |
| 1615 | struct net_device *ndev = priv->ndev; |
| 1616 | |
Wang Dongsheng | 103cdd1 | 2012-11-09 04:43:51 +0000 | [diff] [blame] | 1617 | if (!netif_running(ndev)) { |
| 1618 | netif_device_attach(ndev); |
| 1619 | |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1620 | return 0; |
Wang Dongsheng | 103cdd1 | 2012-11-09 04:43:51 +0000 | [diff] [blame] | 1621 | } |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1622 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 1623 | gfar_init_bds(ndev); |
Claudiu Manoil | 1eb8f7a | 2012-11-08 22:11:41 +0000 | [diff] [blame] | 1624 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 1625 | gfar_mac_reset(priv); |
| 1626 | |
| 1627 | gfar_init_tx_rx_base(priv); |
| 1628 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1629 | gfar_start(priv); |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1630 | |
| 1631 | priv->oldlink = 0; |
| 1632 | priv->oldspeed = 0; |
| 1633 | priv->oldduplex = -1; |
| 1634 | |
| 1635 | if (priv->phydev) |
| 1636 | phy_start(priv->phydev); |
| 1637 | |
| 1638 | netif_device_attach(ndev); |
Anton Vorontsov | 5ea681d | 2009-11-10 14:11:05 +0000 | [diff] [blame] | 1639 | enable_napi(priv); |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | static struct dev_pm_ops gfar_pm_ops = { |
| 1645 | .suspend = gfar_suspend, |
| 1646 | .resume = gfar_resume, |
| 1647 | .freeze = gfar_suspend, |
| 1648 | .thaw = gfar_resume, |
| 1649 | .restore = gfar_restore, |
| 1650 | }; |
| 1651 | |
| 1652 | #define GFAR_PM_OPS (&gfar_pm_ops) |
| 1653 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1654 | #else |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1655 | |
| 1656 | #define GFAR_PM_OPS NULL |
Anton Vorontsov | be926fc | 2009-10-12 06:00:42 +0000 | [diff] [blame] | 1657 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1658 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1660 | /* Reads the controller's registers to determine what interface |
| 1661 | * connects it to the PHY. |
| 1662 | */ |
| 1663 | static phy_interface_t gfar_get_interface(struct net_device *dev) |
| 1664 | { |
| 1665 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1666 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1667 | u32 ecntrl; |
| 1668 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1669 | ecntrl = gfar_read(®s->ecntrl); |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1670 | |
| 1671 | if (ecntrl & ECNTRL_SGMII_MODE) |
| 1672 | return PHY_INTERFACE_MODE_SGMII; |
| 1673 | |
| 1674 | if (ecntrl & ECNTRL_TBI_MODE) { |
| 1675 | if (ecntrl & ECNTRL_REDUCED_MODE) |
| 1676 | return PHY_INTERFACE_MODE_RTBI; |
| 1677 | else |
| 1678 | return PHY_INTERFACE_MODE_TBI; |
| 1679 | } |
| 1680 | |
| 1681 | if (ecntrl & ECNTRL_REDUCED_MODE) { |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1682 | if (ecntrl & ECNTRL_REDUCED_MII_MODE) { |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1683 | return PHY_INTERFACE_MODE_RMII; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1684 | } |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 1685 | else { |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1686 | phy_interface_t interface = priv->interface; |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 1687 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1688 | /* This isn't autodetected right now, so it must |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 1689 | * be set by the device tree or platform code. |
| 1690 | */ |
| 1691 | if (interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 1692 | return PHY_INTERFACE_MODE_RGMII_ID; |
| 1693 | |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1694 | return PHY_INTERFACE_MODE_RGMII; |
Andy Fleming | 7132ab7 | 2007-07-11 11:43:07 -0500 | [diff] [blame] | 1695 | } |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1696 | } |
| 1697 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1698 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT) |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1699 | return PHY_INTERFACE_MODE_GMII; |
| 1700 | |
| 1701 | return PHY_INTERFACE_MODE_MII; |
| 1702 | } |
| 1703 | |
| 1704 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1705 | /* Initializes driver's PHY state, and attaches to the PHY. |
| 1706 | * Returns 0 on success. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | */ |
| 1708 | static int init_phy(struct net_device *dev) |
| 1709 | { |
| 1710 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1711 | uint gigabit_support = |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1712 | priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ? |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 1713 | GFAR_SUPPORTED_GBIT : 0; |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1714 | phy_interface_t interface; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
| 1716 | priv->oldlink = 0; |
| 1717 | priv->oldspeed = 0; |
| 1718 | priv->oldduplex = -1; |
| 1719 | |
Andy Fleming | e8a2b6a | 2006-12-01 12:01:06 -0600 | [diff] [blame] | 1720 | interface = gfar_get_interface(dev); |
| 1721 | |
Anton Vorontsov | 1db780f | 2009-07-16 21:31:42 +0000 | [diff] [blame] | 1722 | priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0, |
| 1723 | interface); |
Anton Vorontsov | 1db780f | 2009-07-16 21:31:42 +0000 | [diff] [blame] | 1724 | if (!priv->phydev) { |
| 1725 | dev_err(&dev->dev, "could not attach to PHY\n"); |
| 1726 | return -ENODEV; |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1729 | if (interface == PHY_INTERFACE_MODE_SGMII) |
| 1730 | gfar_configure_serdes(dev); |
| 1731 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1732 | /* Remove any features not supported by the controller */ |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1733 | priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support); |
| 1734 | priv->phydev->advertising = priv->phydev->supported; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Pavaluca Matei-B46610 | cf987af | 2014-10-27 10:42:42 +0200 | [diff] [blame] | 1736 | /* Add support for flow control, but don't advertise it by default */ |
| 1737 | priv->phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause); |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1742 | /* Initialize TBI PHY interface for communicating with the |
Paul Gortmaker | d031358 | 2008-04-17 00:08:10 -0400 | [diff] [blame] | 1743 | * SERDES lynx PHY on the chip. We communicate with this PHY |
| 1744 | * through the MDIO bus on each controller, treating it as a |
| 1745 | * "normal" PHY at the address found in the TBIPA register. We assume |
| 1746 | * that the TBIPA register is valid. Either the MDIO bus code will set |
| 1747 | * it to a value that doesn't conflict with other PHYs on the bus, or the |
| 1748 | * value doesn't matter, as there are no other PHYs on the bus. |
| 1749 | */ |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1750 | static void gfar_configure_serdes(struct net_device *dev) |
| 1751 | { |
| 1752 | struct gfar_private *priv = netdev_priv(dev); |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1753 | struct phy_device *tbiphy; |
Trent Piepho | c132419 | 2008-10-30 18:17:06 -0700 | [diff] [blame] | 1754 | |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1755 | if (!priv->tbi_node) { |
| 1756 | dev_warn(&dev->dev, "error: SGMII mode requires that the " |
| 1757 | "device tree specify a tbi-handle\n"); |
| 1758 | return; |
| 1759 | } |
| 1760 | |
| 1761 | tbiphy = of_phy_find_device(priv->tbi_node); |
| 1762 | if (!tbiphy) { |
| 1763 | dev_err(&dev->dev, "error: Could not get TBI device\n"); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1764 | return; |
| 1765 | } |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1766 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1767 | /* If the link is already up, we must already be ok, and don't need to |
Trent Piepho | bdb59f9 | 2008-10-30 18:17:07 -0700 | [diff] [blame] | 1768 | * configure and reset the TBI<->SerDes link. Maybe U-Boot configured |
| 1769 | * everything for us? Resetting it takes the link down and requires |
| 1770 | * several seconds for it to come back. |
| 1771 | */ |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1772 | if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS) |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 1773 | return; |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1774 | |
Paul Gortmaker | d031358 | 2008-04-17 00:08:10 -0400 | [diff] [blame] | 1775 | /* Single clk mode, mii mode off(for serdes communication) */ |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1776 | phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT); |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1777 | |
Grant Likely | fe192a4 | 2009-04-25 12:53:12 +0000 | [diff] [blame] | 1778 | phy_write(tbiphy, MII_ADVERTISE, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1779 | ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | |
| 1780 | ADVERTISE_1000XPSE_ASYM); |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1781 | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1782 | phy_write(tbiphy, MII_BMCR, |
| 1783 | BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX | |
| 1784 | BMCR_SPEED1000); |
Kapil Juneja | d3c1287 | 2007-05-11 18:25:11 -0500 | [diff] [blame] | 1785 | } |
| 1786 | |
Anton Vorontsov | 511d934 | 2010-06-30 06:39:15 +0000 | [diff] [blame] | 1787 | static int __gfar_is_rx_idle(struct gfar_private *priv) |
| 1788 | { |
| 1789 | u32 res; |
| 1790 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1791 | /* Normaly TSEC should not hang on GRS commands, so we should |
Anton Vorontsov | 511d934 | 2010-06-30 06:39:15 +0000 | [diff] [blame] | 1792 | * actually wait for IEVENT_GRSC flag. |
| 1793 | */ |
Claudiu Manoil | ad3660c | 2013-10-09 20:20:40 +0300 | [diff] [blame] | 1794 | if (!gfar_has_errata(priv, GFAR_ERRATA_A002)) |
Anton Vorontsov | 511d934 | 2010-06-30 06:39:15 +0000 | [diff] [blame] | 1795 | return 0; |
| 1796 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1797 | /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are |
Anton Vorontsov | 511d934 | 2010-06-30 06:39:15 +0000 | [diff] [blame] | 1798 | * the same as bits 23-30, the eTSEC Rx is assumed to be idle |
| 1799 | * and the Rx can be safely reset. |
| 1800 | */ |
| 1801 | res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c); |
| 1802 | res &= 0x7f807f80; |
| 1803 | if ((res & 0xffff) == (res >> 16)) |
| 1804 | return 1; |
| 1805 | |
| 1806 | return 0; |
| 1807 | } |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1808 | |
| 1809 | /* Halt the receive and transmit queues */ |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1810 | static void gfar_halt_nodisable(struct gfar_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | { |
Claudiu Manoil | efeddce | 2014-02-17 12:53:17 +0200 | [diff] [blame] | 1812 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | u32 tempval; |
Claudiu Manoil | a4feee8 | 2014-10-07 10:44:34 +0300 | [diff] [blame] | 1814 | unsigned int timeout; |
| 1815 | int stopped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | |
Claudiu Manoil | efeddce | 2014-02-17 12:53:17 +0200 | [diff] [blame] | 1817 | gfar_ints_disable(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | |
Claudiu Manoil | a4feee8 | 2014-10-07 10:44:34 +0300 | [diff] [blame] | 1819 | if (gfar_is_dma_stopped(priv)) |
| 1820 | return; |
| 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | /* Stop the DMA, and wait for it to stop */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1823 | tempval = gfar_read(®s->dmactrl); |
Claudiu Manoil | a4feee8 | 2014-10-07 10:44:34 +0300 | [diff] [blame] | 1824 | tempval |= (DMACTRL_GRS | DMACTRL_GTS); |
| 1825 | gfar_write(®s->dmactrl, tempval); |
Anton Vorontsov | 511d934 | 2010-06-30 06:39:15 +0000 | [diff] [blame] | 1826 | |
Claudiu Manoil | a4feee8 | 2014-10-07 10:44:34 +0300 | [diff] [blame] | 1827 | retry: |
| 1828 | timeout = 1000; |
| 1829 | while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) { |
| 1830 | cpu_relax(); |
| 1831 | timeout--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
Claudiu Manoil | a4feee8 | 2014-10-07 10:44:34 +0300 | [diff] [blame] | 1833 | |
| 1834 | if (!timeout) |
| 1835 | stopped = gfar_is_dma_stopped(priv); |
| 1836 | |
| 1837 | if (!stopped && !gfar_is_rx_dma_stopped(priv) && |
| 1838 | !__gfar_is_rx_idle(priv)) |
| 1839 | goto retry; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1840 | } |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1841 | |
| 1842 | /* Halt the receive and transmit queues */ |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1843 | void gfar_halt(struct gfar_private *priv) |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1844 | { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1845 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1846 | u32 tempval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1848 | /* Dissable the Rx/Tx hw queues */ |
| 1849 | gfar_write(®s->rqueue, 0); |
| 1850 | gfar_write(®s->tqueue, 0); |
Scott Wood | 2a54adc | 2008-08-12 15:10:46 -0500 | [diff] [blame] | 1851 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1852 | mdelay(10); |
| 1853 | |
| 1854 | gfar_halt_nodisable(priv); |
| 1855 | |
| 1856 | /* Disable Rx/Tx DMA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | tempval = gfar_read(®s->maccfg1); |
| 1858 | tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 1859 | gfar_write(®s->maccfg1, tempval); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | void stop_gfar(struct net_device *dev) |
| 1863 | { |
| 1864 | struct gfar_private *priv = netdev_priv(dev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1865 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1866 | netif_tx_stop_all_queues(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1867 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 1868 | smp_mb__before_atomic(); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1869 | set_bit(GFAR_DOWN, &priv->state); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 1870 | smp_mb__after_atomic(); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1871 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1872 | disable_napi(priv); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1873 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1874 | /* disable ints and gracefully shut down Rx/Tx DMA */ |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1875 | gfar_halt(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1877 | phy_stop(priv->phydev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | free_skb_resources(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1882 | static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | struct txbd8 *txbdp; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1885 | struct gfar_private *priv = netdev_priv(tx_queue->dev); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 1886 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1888 | txbdp = tx_queue->tx_bd_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1890 | for (i = 0; i < tx_queue->tx_ring_size; i++) { |
| 1891 | if (!tx_queue->tx_skbuff[i]) |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 1892 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 1894 | dma_unmap_single(priv->dev, be32_to_cpu(txbdp->bufPtr), |
| 1895 | be16_to_cpu(txbdp->length), DMA_TO_DEVICE); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 1896 | txbdp->lstatus = 0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1897 | for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1898 | j++) { |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 1899 | txbdp++; |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 1900 | dma_unmap_page(priv->dev, be32_to_cpu(txbdp->bufPtr), |
| 1901 | be16_to_cpu(txbdp->length), |
| 1902 | DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
Andy Fleming | ad5da7a | 2008-05-07 13:20:55 -0500 | [diff] [blame] | 1904 | txbdp++; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1905 | dev_kfree_skb_any(tx_queue->tx_skbuff[i]); |
| 1906 | tx_queue->tx_skbuff[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1908 | kfree(tx_queue->tx_skbuff); |
Claudiu Manoil | 1eb8f7a | 2012-11-08 22:11:41 +0000 | [diff] [blame] | 1909 | tx_queue->tx_skbuff = NULL; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1912 | static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue) |
| 1913 | { |
| 1914 | struct rxbd8 *rxbdp; |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 1915 | struct gfar_private *priv = netdev_priv(rx_queue->ndev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1916 | int i; |
| 1917 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1918 | rxbdp = rx_queue->rx_bd_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1920 | for (i = 0; i < rx_queue->rx_ring_size; i++) { |
| 1921 | if (rx_queue->rx_skbuff[i]) { |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 1922 | dma_unmap_single(priv->dev, be32_to_cpu(rxbdp->bufPtr), |
Claudiu Manoil | 369ec16 | 2013-02-14 05:00:02 +0000 | [diff] [blame] | 1923 | priv->rx_buffer_size, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1924 | DMA_FROM_DEVICE); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1925 | dev_kfree_skb_any(rx_queue->rx_skbuff[i]); |
| 1926 | rx_queue->rx_skbuff[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | } |
Anton Vorontsov | e69edd2 | 2009-10-12 06:00:30 +0000 | [diff] [blame] | 1928 | rxbdp->lstatus = 0; |
| 1929 | rxbdp->bufPtr = 0; |
| 1930 | rxbdp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 1932 | kfree(rx_queue->rx_skbuff); |
Claudiu Manoil | 1eb8f7a | 2012-11-08 22:11:41 +0000 | [diff] [blame] | 1933 | rx_queue->rx_skbuff = NULL; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1934 | } |
Anton Vorontsov | e69edd2 | 2009-10-12 06:00:30 +0000 | [diff] [blame] | 1935 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1936 | /* If there are any tx skbs or rx skbs still around, free them. |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 1937 | * Then free tx_skbuff and rx_skbuff |
| 1938 | */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1939 | static void free_skb_resources(struct gfar_private *priv) |
| 1940 | { |
| 1941 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 1942 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 1943 | int i; |
| 1944 | |
| 1945 | /* Go through all the buffer descriptors and free their data buffers */ |
| 1946 | for (i = 0; i < priv->num_tx_queues; i++) { |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 1947 | struct netdev_queue *txq; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1948 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1949 | tx_queue = priv->tx_queue[i]; |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 1950 | txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1951 | if (tx_queue->tx_skbuff) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1952 | free_skb_tx_queue(tx_queue); |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 1953 | netdev_tx_reset_queue(txq); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 1957 | rx_queue = priv->rx_queue[i]; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1958 | if (rx_queue->rx_skbuff) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 1959 | free_skb_rx_queue(rx_queue); |
| 1960 | } |
| 1961 | |
Claudiu Manoil | 369ec16 | 2013-02-14 05:00:02 +0000 | [diff] [blame] | 1962 | dma_free_coherent(priv->dev, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 1963 | sizeof(struct txbd8) * priv->total_tx_ring_size + |
| 1964 | sizeof(struct rxbd8) * priv->total_rx_ring_size, |
| 1965 | priv->tx_queue[0]->tx_bd_base, |
| 1966 | priv->tx_queue[0]->tx_bd_dma_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1969 | void gfar_start(struct gfar_private *priv) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1970 | { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1971 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1972 | u32 tempval; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1973 | int i = 0; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1974 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1975 | /* Enable Rx/Tx hw queues */ |
| 1976 | gfar_write(®s->rqueue, priv->rqueue); |
| 1977 | gfar_write(®s->tqueue, priv->tqueue); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1978 | |
| 1979 | /* Initialize DMACTRL to have WWR and WOP */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1980 | tempval = gfar_read(®s->dmactrl); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1981 | tempval |= DMACTRL_INIT_SETTINGS; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1982 | gfar_write(®s->dmactrl, tempval); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1983 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1984 | /* Make sure we aren't stopped */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1985 | tempval = gfar_read(®s->dmactrl); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1986 | tempval &= ~(DMACTRL_GRS | DMACTRL_GTS); |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 1987 | gfar_write(®s->dmactrl, tempval); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1988 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1989 | for (i = 0; i < priv->num_grps; i++) { |
| 1990 | regs = priv->gfargrp[i].regs; |
| 1991 | /* Clear THLT/RHLT, so that the DMA starts polling now */ |
| 1992 | gfar_write(®s->tstat, priv->gfargrp[i].tstat); |
| 1993 | gfar_write(®s->rstat, priv->gfargrp[i].rstat); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 1994 | } |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 1995 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 1996 | /* Enable Rx/Tx DMA */ |
| 1997 | tempval = gfar_read(®s->maccfg1); |
| 1998 | tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 1999 | gfar_write(®s->maccfg1, tempval); |
| 2000 | |
Claudiu Manoil | efeddce | 2014-02-17 12:53:17 +0200 | [diff] [blame] | 2001 | gfar_ints_enable(priv); |
| 2002 | |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 2003 | priv->ndev->trans_start = jiffies; /* prevent tx timeout */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2004 | } |
| 2005 | |
Claudiu Manoil | 80ec396 | 2014-02-24 12:13:44 +0200 | [diff] [blame] | 2006 | static void free_grp_irqs(struct gfar_priv_grp *grp) |
| 2007 | { |
| 2008 | free_irq(gfar_irq(grp, TX)->irq, grp); |
| 2009 | free_irq(gfar_irq(grp, RX)->irq, grp); |
| 2010 | free_irq(gfar_irq(grp, ER)->irq, grp); |
| 2011 | } |
| 2012 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2013 | static int register_grp_irqs(struct gfar_priv_grp *grp) |
| 2014 | { |
| 2015 | struct gfar_private *priv = grp->priv; |
| 2016 | struct net_device *dev = priv->ndev; |
Anton Vorontsov | ccc05c6 | 2009-10-12 06:00:26 +0000 | [diff] [blame] | 2017 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | /* If the device has multiple interrupts, register for |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2020 | * them. Otherwise, only register for the one |
| 2021 | */ |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 2022 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2023 | /* Install our interrupt handlers for Error, |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2024 | * Transmit, and Receive |
| 2025 | */ |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2026 | err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0, |
| 2027 | gfar_irq(grp, ER)->name, grp); |
| 2028 | if (err < 0) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 2029 | netif_err(priv, intr, dev, "Can't get IRQ %d\n", |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2030 | gfar_irq(grp, ER)->irq); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2031 | |
Julia Lawall | 2145f1a | 2010-08-05 10:26:20 +0000 | [diff] [blame] | 2032 | goto err_irq_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | } |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2034 | err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0, |
| 2035 | gfar_irq(grp, TX)->name, grp); |
| 2036 | if (err < 0) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 2037 | netif_err(priv, intr, dev, "Can't get IRQ %d\n", |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2038 | gfar_irq(grp, TX)->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | goto tx_irq_fail; |
| 2040 | } |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2041 | err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0, |
| 2042 | gfar_irq(grp, RX)->name, grp); |
| 2043 | if (err < 0) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 2044 | netif_err(priv, intr, dev, "Can't get IRQ %d\n", |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2045 | gfar_irq(grp, RX)->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | goto rx_irq_fail; |
| 2047 | } |
| 2048 | } else { |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2049 | err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0, |
| 2050 | gfar_irq(grp, TX)->name, grp); |
| 2051 | if (err < 0) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 2052 | netif_err(priv, intr, dev, "Can't get IRQ %d\n", |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2053 | gfar_irq(grp, TX)->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | goto err_irq_fail; |
| 2055 | } |
| 2056 | } |
| 2057 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2058 | return 0; |
| 2059 | |
| 2060 | rx_irq_fail: |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2061 | free_irq(gfar_irq(grp, TX)->irq, grp); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2062 | tx_irq_fail: |
Claudiu Manoil | ee873fd | 2013-01-29 03:55:12 +0000 | [diff] [blame] | 2063 | free_irq(gfar_irq(grp, ER)->irq, grp); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2064 | err_irq_fail: |
| 2065 | return err; |
| 2066 | |
| 2067 | } |
| 2068 | |
Claudiu Manoil | 80ec396 | 2014-02-24 12:13:44 +0200 | [diff] [blame] | 2069 | static void gfar_free_irq(struct gfar_private *priv) |
| 2070 | { |
| 2071 | int i; |
| 2072 | |
| 2073 | /* Free the IRQs */ |
| 2074 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { |
| 2075 | for (i = 0; i < priv->num_grps; i++) |
| 2076 | free_grp_irqs(&priv->gfargrp[i]); |
| 2077 | } else { |
| 2078 | for (i = 0; i < priv->num_grps; i++) |
| 2079 | free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq, |
| 2080 | &priv->gfargrp[i]); |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | static int gfar_request_irq(struct gfar_private *priv) |
| 2085 | { |
| 2086 | int err, i, j; |
| 2087 | |
| 2088 | for (i = 0; i < priv->num_grps; i++) { |
| 2089 | err = register_grp_irqs(&priv->gfargrp[i]); |
| 2090 | if (err) { |
| 2091 | for (j = 0; j < i; j++) |
| 2092 | free_grp_irqs(&priv->gfargrp[j]); |
| 2093 | return err; |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | return 0; |
| 2098 | } |
| 2099 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2100 | /* Bring the controller up and running */ |
| 2101 | int startup_gfar(struct net_device *ndev) |
| 2102 | { |
| 2103 | struct gfar_private *priv = netdev_priv(ndev); |
Claudiu Manoil | 80ec396 | 2014-02-24 12:13:44 +0200 | [diff] [blame] | 2104 | int err; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2105 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 2106 | gfar_mac_reset(priv); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2107 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2108 | err = gfar_alloc_skb_resources(ndev); |
| 2109 | if (err) |
| 2110 | return err; |
| 2111 | |
Claudiu Manoil | a328ac9 | 2014-02-24 12:13:42 +0200 | [diff] [blame] | 2112 | gfar_init_tx_rx_base(priv); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2113 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 2114 | smp_mb__before_atomic(); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2115 | clear_bit(GFAR_DOWN, &priv->state); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 2116 | smp_mb__after_atomic(); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2117 | |
| 2118 | /* Start Rx/Tx DMA and enable the interrupts */ |
Claudiu Manoil | c10650b | 2014-02-17 12:53:18 +0200 | [diff] [blame] | 2119 | gfar_start(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | |
Anton Vorontsov | 826aa4a | 2009-10-12 06:00:34 +0000 | [diff] [blame] | 2121 | phy_start(priv->phydev); |
| 2122 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2123 | enable_napi(priv); |
| 2124 | |
| 2125 | netif_tx_wake_all_queues(ndev); |
| 2126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2130 | /* Called when something needs to use the ethernet device |
| 2131 | * Returns 0 for success. |
| 2132 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | static int gfar_enet_open(struct net_device *dev) |
| 2134 | { |
Li Yang | 94e8cc3 | 2007-10-12 21:53:51 +0800 | [diff] [blame] | 2135 | struct gfar_private *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | int err; |
| 2137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | err = init_phy(dev); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2139 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | return err; |
| 2141 | |
Claudiu Manoil | 80ec396 | 2014-02-24 12:13:44 +0200 | [diff] [blame] | 2142 | err = gfar_request_irq(priv); |
| 2143 | if (err) |
| 2144 | return err; |
| 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | err = startup_gfar(dev); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2147 | if (err) |
Anton Vorontsov | db0e8e3 | 2007-10-17 23:57:46 +0400 | [diff] [blame] | 2148 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | |
Anton Vorontsov | 2884e5c | 2009-02-01 00:52:34 -0800 | [diff] [blame] | 2150 | device_set_wakeup_enable(&dev->dev, priv->wol_en); |
| 2151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | return err; |
| 2153 | } |
| 2154 | |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2155 | static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2156 | { |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2157 | struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN); |
Kumar Gala | 6c31d55 | 2009-04-28 08:04:10 -0700 | [diff] [blame] | 2158 | |
| 2159 | memset(fcb, 0, GMAC_FCB_LEN); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2160 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2161 | return fcb; |
| 2162 | } |
| 2163 | |
Manfred Rudigier | 9c4886e | 2012-01-09 23:26:51 +0000 | [diff] [blame] | 2164 | static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2165 | int fcb_length) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2166 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2167 | /* If we're here, it's a IP packet with a TCP or UDP |
| 2168 | * payload. We set it to checksum, using a pseudo-header |
| 2169 | * we provide |
| 2170 | */ |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 2171 | u8 flags = TXFCB_DEFAULT; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2172 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2173 | /* Tell the controller what the protocol is |
| 2174 | * And provide the already calculated phcs |
| 2175 | */ |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2176 | if (ip_hdr(skb)->protocol == IPPROTO_UDP) { |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2177 | flags |= TXFCB_UDP; |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2178 | fcb->phcs = (__force __be16)(udp_hdr(skb)->check); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2179 | } else |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2180 | fcb->phcs = (__force __be16)(tcp_hdr(skb)->check); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2181 | |
| 2182 | /* l3os is the distance between the start of the |
| 2183 | * frame (skb->data) and the start of the IP hdr. |
| 2184 | * l4os is the distance between the start of the |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2185 | * l3 hdr and the l4 hdr |
| 2186 | */ |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2187 | fcb->l3os = (u8)(skb_network_offset(skb) - fcb_length); |
Arnaldo Carvalho de Melo | cfe1fc7 | 2007-03-16 17:26:39 -0300 | [diff] [blame] | 2188 | fcb->l4os = skb_network_header_len(skb); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2189 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2190 | fcb->flags = flags; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2193 | void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2194 | { |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2195 | fcb->flags |= TXFCB_VLN; |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2196 | fcb->vlctl = cpu_to_be16(skb_vlan_tag_get(skb)); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2197 | } |
| 2198 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2199 | static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2200 | struct txbd8 *base, int ring_size) |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2201 | { |
| 2202 | struct txbd8 *new_bd = bdp + stride; |
| 2203 | |
| 2204 | return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd; |
| 2205 | } |
| 2206 | |
| 2207 | static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2208 | int ring_size) |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2209 | { |
| 2210 | return skip_txbd(bdp, 1, base, ring_size); |
| 2211 | } |
| 2212 | |
Claudiu Manoil | 02d88fb | 2013-08-05 17:20:09 +0300 | [diff] [blame] | 2213 | /* eTSEC12: csum generation not supported for some fcb offsets */ |
| 2214 | static inline bool gfar_csum_errata_12(struct gfar_private *priv, |
| 2215 | unsigned long fcb_addr) |
| 2216 | { |
| 2217 | return (gfar_has_errata(priv, GFAR_ERRATA_12) && |
| 2218 | (fcb_addr % 0x20) > 0x18); |
| 2219 | } |
| 2220 | |
| 2221 | /* eTSEC76: csum generation for frames larger than 2500 may |
| 2222 | * cause excess delays before start of transmission |
| 2223 | */ |
| 2224 | static inline bool gfar_csum_errata_76(struct gfar_private *priv, |
| 2225 | unsigned int len) |
| 2226 | { |
| 2227 | return (gfar_has_errata(priv, GFAR_ERRATA_76) && |
| 2228 | (len > 2500)); |
| 2229 | } |
| 2230 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2231 | /* This is called by the kernel when a frame is ready for transmission. |
| 2232 | * It is pointed to by the dev->hard_start_xmit function pointer |
| 2233 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 2235 | { |
| 2236 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2237 | struct gfar_priv_tx_q *tx_queue = NULL; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 2238 | struct netdev_queue *txq; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 2239 | struct gfar __iomem *regs = NULL; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2240 | struct txfcb *fcb = NULL; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2241 | struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL; |
Dai Haruki | 5a5efed | 2008-12-16 15:34:50 -0800 | [diff] [blame] | 2242 | u32 lstatus; |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2243 | int i, rq = 0; |
| 2244 | int do_tstamp, do_csum, do_vlan; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2245 | u32 bufaddr; |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2246 | unsigned int nr_frags, nr_txbds, bytes_sent, fcb_len = 0; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 2247 | |
| 2248 | rq = skb->queue_mapping; |
| 2249 | tx_queue = priv->tx_queue[rq]; |
| 2250 | txq = netdev_get_tx_queue(dev, rq); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2251 | base = tx_queue->tx_bd_base; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 2252 | regs = tx_queue->grp->regs; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2253 | |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2254 | do_csum = (CHECKSUM_PARTIAL == skb->ip_summed); |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 2255 | do_vlan = skb_vlan_tag_present(skb); |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2256 | do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 2257 | priv->hwts_tx_en; |
| 2258 | |
| 2259 | if (do_csum || do_vlan) |
| 2260 | fcb_len = GMAC_FCB_LEN; |
| 2261 | |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2262 | /* check if time stamp should be generated */ |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2263 | if (unlikely(do_tstamp)) |
| 2264 | fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2265 | |
Li Yang | 5b28bea | 2009-03-27 15:54:30 -0700 | [diff] [blame] | 2266 | /* make space for additional header when fcb is needed */ |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2267 | if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) { |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2268 | struct sk_buff *skb_new; |
| 2269 | |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2270 | skb_new = skb_realloc_headroom(skb, fcb_len); |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2271 | if (!skb_new) { |
| 2272 | dev->stats.tx_errors++; |
Eric W. Biederman | c9974ad | 2014-03-11 14:20:26 -0700 | [diff] [blame] | 2273 | dev_kfree_skb_any(skb); |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2274 | return NETDEV_TX_OK; |
| 2275 | } |
Manfred Rudigier | db83d13 | 2012-01-09 23:26:50 +0000 | [diff] [blame] | 2276 | |
Eric Dumazet | 313b037 | 2012-07-05 11:45:13 +0000 | [diff] [blame] | 2277 | if (skb->sk) |
| 2278 | skb_set_owner_w(skb_new, skb->sk); |
Eric W. Biederman | c9974ad | 2014-03-11 14:20:26 -0700 | [diff] [blame] | 2279 | dev_consume_skb_any(skb); |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2280 | skb = skb_new; |
| 2281 | } |
| 2282 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2283 | /* total number of fragments in the SKB */ |
| 2284 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 2285 | |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2286 | /* calculate the required number of TxBDs for this skb */ |
| 2287 | if (unlikely(do_tstamp)) |
| 2288 | nr_txbds = nr_frags + 2; |
| 2289 | else |
| 2290 | nr_txbds = nr_frags + 1; |
| 2291 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2292 | /* check if there is space to queue this packet */ |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2293 | if (nr_txbds > tx_queue->num_txbdfree) { |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2294 | /* no space, stop the queue */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 2295 | netif_tx_stop_queue(txq); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2296 | dev->stats.tx_fifo_errors++; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2297 | return NETDEV_TX_BUSY; |
| 2298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | |
| 2300 | /* Update transmit stats */ |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2301 | bytes_sent = skb->len; |
| 2302 | tx_queue->stats.tx_bytes += bytes_sent; |
| 2303 | /* keep Tx bytes on wire for BQL accounting */ |
| 2304 | GFAR_CB(skb)->bytes_sent = bytes_sent; |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 2305 | tx_queue->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2307 | txbdp = txbdp_start = tx_queue->cur_tx; |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2308 | lstatus = be32_to_cpu(txbdp->lstatus); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2309 | |
| 2310 | /* Time stamp insertion requires one additional TxBD */ |
| 2311 | if (unlikely(do_tstamp)) |
| 2312 | txbdp_tstamp = txbdp = next_txbd(txbdp, base, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2313 | tx_queue->tx_ring_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2315 | if (nr_frags == 0) { |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2316 | if (unlikely(do_tstamp)) { |
| 2317 | u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus); |
| 2318 | |
| 2319 | lstatus_ts |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); |
| 2320 | txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts); |
| 2321 | } else { |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2322 | lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2323 | } |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2324 | } else { |
| 2325 | /* Place the fragment addresses and lengths into the TxBDs */ |
| 2326 | for (i = 0; i < nr_frags; i++) { |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2327 | unsigned int frag_len; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2328 | /* Point at the next BD, wrapping as needed */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2329 | txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2331 | frag_len = skb_shinfo(skb)->frags[i].size; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2332 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2333 | lstatus = be32_to_cpu(txbdp->lstatus) | frag_len | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2334 | BD_LFLAG(TXBD_READY); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2335 | |
| 2336 | /* Handle the last BD specially */ |
| 2337 | if (i == nr_frags - 1) |
| 2338 | lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); |
| 2339 | |
Claudiu Manoil | 369ec16 | 2013-02-14 05:00:02 +0000 | [diff] [blame] | 2340 | bufaddr = skb_frag_dma_map(priv->dev, |
Ian Campbell | 2234a72 | 2011-08-29 23:18:29 +0000 | [diff] [blame] | 2341 | &skb_shinfo(skb)->frags[i], |
| 2342 | 0, |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2343 | frag_len, |
Ian Campbell | 2234a72 | 2011-08-29 23:18:29 +0000 | [diff] [blame] | 2344 | DMA_TO_DEVICE); |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2345 | if (unlikely(dma_mapping_error(priv->dev, bufaddr))) |
| 2346 | goto dma_map_err; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2347 | |
| 2348 | /* set the TxBD length and buffer pointer */ |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2349 | txbdp->bufPtr = cpu_to_be32(bufaddr); |
| 2350 | txbdp->lstatus = cpu_to_be32(lstatus); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2351 | } |
| 2352 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2353 | lstatus = be32_to_cpu(txbdp_start->lstatus); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
Manfred Rudigier | 9c4886e | 2012-01-09 23:26:51 +0000 | [diff] [blame] | 2356 | /* Add TxPAL between FCB and frame if required */ |
| 2357 | if (unlikely(do_tstamp)) { |
| 2358 | skb_push(skb, GMAC_TXPAL_LEN); |
| 2359 | memset(skb->data, 0, GMAC_TXPAL_LEN); |
| 2360 | } |
| 2361 | |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2362 | /* Add TxFCB if required */ |
| 2363 | if (fcb_len) { |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2364 | fcb = gfar_add_fcb(skb); |
Claudiu Manoil | 02d88fb | 2013-08-05 17:20:09 +0300 | [diff] [blame] | 2365 | lstatus |= BD_LFLAG(TXBD_TOE); |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | /* Set up checksumming */ |
| 2369 | if (do_csum) { |
| 2370 | gfar_tx_checksum(skb, fcb, fcb_len); |
Claudiu Manoil | 02d88fb | 2013-08-05 17:20:09 +0300 | [diff] [blame] | 2371 | |
| 2372 | if (unlikely(gfar_csum_errata_12(priv, (unsigned long)fcb)) || |
| 2373 | unlikely(gfar_csum_errata_76(priv, skb->len))) { |
Alex Dubov | 4363c2fdd | 2011-03-16 17:57:13 +0000 | [diff] [blame] | 2374 | __skb_pull(skb, GMAC_FCB_LEN); |
| 2375 | skb_checksum_help(skb); |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2376 | if (do_vlan || do_tstamp) { |
| 2377 | /* put back a new fcb for vlan/tstamp TOE */ |
| 2378 | fcb = gfar_add_fcb(skb); |
| 2379 | } else { |
| 2380 | /* Tx TOE not used */ |
| 2381 | lstatus &= ~(BD_LFLAG(TXBD_TOE)); |
| 2382 | fcb = NULL; |
| 2383 | } |
Alex Dubov | 4363c2fdd | 2011-03-16 17:57:13 +0000 | [diff] [blame] | 2384 | } |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2385 | } |
| 2386 | |
Claudiu Manoil | 0d0cffd | 2013-08-05 17:20:10 +0300 | [diff] [blame] | 2387 | if (do_vlan) |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2388 | gfar_tx_vlan(skb, fcb); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2389 | |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2390 | /* Setup tx hardware time stamping if requested */ |
| 2391 | if (unlikely(do_tstamp)) { |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 2392 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2393 | fcb->ptp = 1; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2396 | bufaddr = dma_map_single(priv->dev, skb->data, skb_headlen(skb), |
| 2397 | DMA_TO_DEVICE); |
| 2398 | if (unlikely(dma_mapping_error(priv->dev, bufaddr))) |
| 2399 | goto dma_map_err; |
| 2400 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2401 | txbdp_start->bufPtr = cpu_to_be32(bufaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2403 | /* If time stamping is requested one additional TxBD must be set up. The |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2404 | * first TxBD points to the FCB and must have a data length of |
| 2405 | * GMAC_FCB_LEN. The second TxBD points to the actual frame data with |
| 2406 | * the full frame length. |
| 2407 | */ |
| 2408 | if (unlikely(do_tstamp)) { |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2409 | u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus); |
| 2410 | |
| 2411 | bufaddr = be32_to_cpu(txbdp_start->bufPtr); |
| 2412 | bufaddr += fcb_len; |
| 2413 | lstatus_ts |= BD_LFLAG(TXBD_READY) | |
| 2414 | (skb_headlen(skb) - fcb_len); |
| 2415 | |
| 2416 | txbdp_tstamp->bufPtr = cpu_to_be32(bufaddr); |
| 2417 | txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2418 | lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN; |
| 2419 | } else { |
| 2420 | lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb); |
| 2421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2423 | netdev_tx_sent_queue(txq, bytes_sent); |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2424 | |
Claudiu Manoil | d55398b | 2014-10-07 10:44:35 +0300 | [diff] [blame] | 2425 | gfar_wmb(); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2426 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2427 | txbdp_start->lstatus = cpu_to_be32(lstatus); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2428 | |
Claudiu Manoil | d55398b | 2014-10-07 10:44:35 +0300 | [diff] [blame] | 2429 | gfar_wmb(); /* force lstatus write before tx_skbuff */ |
Anton Vorontsov | 0eddba5 | 2010-03-03 08:18:58 +0000 | [diff] [blame] | 2430 | |
| 2431 | tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb; |
| 2432 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2433 | /* Update the current skb pointer to the next entry we will use |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2434 | * (wrapping if necessary) |
| 2435 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2436 | tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) & |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2437 | TX_RING_MOD_MASK(tx_queue->tx_ring_size); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2438 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2439 | tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2440 | |
Claudiu Manoil | bc60228 | 2015-05-06 18:07:29 +0300 | [diff] [blame] | 2441 | /* We can work in parallel with gfar_clean_tx_ring(), except |
| 2442 | * when modifying num_txbdfree. Note that we didn't grab the lock |
| 2443 | * when we were reading the num_txbdfree and checking for available |
| 2444 | * space, that's because outside of this function it can only grow. |
| 2445 | */ |
| 2446 | spin_lock_bh(&tx_queue->txlock); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2447 | /* reduce TxBD free count */ |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2448 | tx_queue->num_txbdfree -= (nr_txbds); |
Claudiu Manoil | bc60228 | 2015-05-06 18:07:29 +0300 | [diff] [blame] | 2449 | spin_unlock_bh(&tx_queue->txlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | |
| 2451 | /* If the next BD still needs to be cleaned up, then the bds |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2452 | * are full. We need to tell the kernel to stop sending us stuff. |
| 2453 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2454 | if (!tx_queue->num_txbdfree) { |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 2455 | netif_tx_stop_queue(txq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 2457 | dev->stats.tx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | /* Tell the DMA to go go go */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 2461 | gfar_write(®s->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
Stephen Hemminger | 54dc79f | 2009-03-27 00:38:45 -0700 | [diff] [blame] | 2463 | return NETDEV_TX_OK; |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2464 | |
| 2465 | dma_map_err: |
| 2466 | txbdp = next_txbd(txbdp_start, base, tx_queue->tx_ring_size); |
| 2467 | if (do_tstamp) |
| 2468 | txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size); |
| 2469 | for (i = 0; i < nr_frags; i++) { |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2470 | lstatus = be32_to_cpu(txbdp->lstatus); |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2471 | if (!(lstatus & BD_LFLAG(TXBD_READY))) |
| 2472 | break; |
| 2473 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2474 | lstatus &= ~BD_LFLAG(TXBD_READY); |
| 2475 | txbdp->lstatus = cpu_to_be32(lstatus); |
| 2476 | bufaddr = be32_to_cpu(txbdp->bufPtr); |
| 2477 | dma_unmap_page(priv->dev, bufaddr, be16_to_cpu(txbdp->length), |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2478 | DMA_TO_DEVICE); |
| 2479 | txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size); |
| 2480 | } |
| 2481 | gfar_wmb(); |
| 2482 | dev_kfree_skb_any(skb); |
| 2483 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | /* Stops the kernel queue, and halts the controller */ |
| 2487 | static int gfar_close(struct net_device *dev) |
| 2488 | { |
| 2489 | struct gfar_private *priv = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2490 | |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 2491 | cancel_work_sync(&priv->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | stop_gfar(dev); |
| 2493 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 2494 | /* Disconnect from the PHY */ |
| 2495 | phy_disconnect(priv->phydev); |
| 2496 | priv->phydev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Claudiu Manoil | 80ec396 | 2014-02-24 12:13:44 +0200 | [diff] [blame] | 2498 | gfar_free_irq(priv); |
| 2499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | return 0; |
| 2501 | } |
| 2502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | /* Changes the mac address if the controller is not running. */ |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 2504 | static int gfar_set_mac_address(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | { |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 2506 | gfar_set_mac_for_addr(dev, 0, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | static int gfar_change_mtu(struct net_device *dev, int new_mtu) |
| 2512 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | struct gfar_private *priv = netdev_priv(dev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2514 | int frame_size = new_mtu + ETH_HLEN; |
| 2515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 2517 | netif_err(priv, drv, dev, "Invalid MTU setting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | return -EINVAL; |
| 2519 | } |
| 2520 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2521 | while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state)) |
| 2522 | cpu_relax(); |
| 2523 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 2524 | if (dev->flags & IFF_UP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | stop_gfar(dev); |
| 2526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | dev->mtu = new_mtu; |
| 2528 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 2529 | if (dev->flags & IFF_UP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | startup_gfar(dev); |
| 2531 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2532 | clear_bit_unlock(GFAR_RESETTING, &priv->state); |
| 2533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | return 0; |
| 2535 | } |
| 2536 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2537 | void reset_gfar(struct net_device *ndev) |
| 2538 | { |
| 2539 | struct gfar_private *priv = netdev_priv(ndev); |
| 2540 | |
| 2541 | while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state)) |
| 2542 | cpu_relax(); |
| 2543 | |
| 2544 | stop_gfar(ndev); |
| 2545 | startup_gfar(ndev); |
| 2546 | |
| 2547 | clear_bit_unlock(GFAR_RESETTING, &priv->state); |
| 2548 | } |
| 2549 | |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 2550 | /* gfar_reset_task gets scheduled when a packet has not been |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | * transmitted after a set amount of time. |
| 2552 | * For now, assume that clearing out all the structures, and |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 2553 | * starting over will fix the problem. |
| 2554 | */ |
| 2555 | static void gfar_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | { |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 2557 | struct gfar_private *priv = container_of(work, struct gfar_private, |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2558 | reset_task); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2559 | reset_gfar(priv->ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Sebastian Siewior | ab93990 | 2008-08-19 21:12:45 +0200 | [diff] [blame] | 2562 | static void gfar_timeout(struct net_device *dev) |
| 2563 | { |
| 2564 | struct gfar_private *priv = netdev_priv(dev); |
| 2565 | |
| 2566 | dev->stats.tx_errors++; |
| 2567 | schedule_work(&priv->reset_task); |
| 2568 | } |
| 2569 | |
Eran Liberty | acbc0f0 | 2010-07-07 15:54:54 -0700 | [diff] [blame] | 2570 | static void gfar_align_skb(struct sk_buff *skb) |
| 2571 | { |
| 2572 | /* We need the data buffer to be aligned properly. We will reserve |
| 2573 | * as many bytes as needed to align the data properly |
| 2574 | */ |
| 2575 | skb_reserve(skb, RXBUF_ALIGNMENT - |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2576 | (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1))); |
Eran Liberty | acbc0f0 | 2010-07-07 15:54:54 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | /* Interrupt Handler for Transmit complete */ |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 2580 | static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | { |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2582 | struct net_device *dev = tx_queue->dev; |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2583 | struct netdev_queue *txq; |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 2584 | struct gfar_private *priv = netdev_priv(dev); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2585 | struct txbd8 *bdp, *next = NULL; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2586 | struct txbd8 *lbdp = NULL; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2587 | struct txbd8 *base = tx_queue->tx_bd_base; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2588 | struct sk_buff *skb; |
| 2589 | int skb_dirtytx; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2590 | int tx_ring_size = tx_queue->tx_ring_size; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2591 | int frags = 0, nr_txbds = 0; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2592 | int i; |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 2593 | int howmany = 0; |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2594 | int tqi = tx_queue->qindex; |
| 2595 | unsigned int bytes_sent = 0; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2596 | u32 lstatus; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2597 | size_t buflen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2599 | txq = netdev_get_tx_queue(dev, tqi); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2600 | bdp = tx_queue->dirty_tx; |
| 2601 | skb_dirtytx = tx_queue->skb_dirtytx; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2602 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2603 | while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) { |
Anton Vorontsov | a3bc1f1 | 2009-11-10 14:11:10 +0000 | [diff] [blame] | 2604 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2605 | frags = skb_shinfo(skb)->nr_frags; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2606 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2607 | /* When time stamping, one additional TxBD must be freed. |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2608 | * Also, we need to dma_unmap_single() the TxPAL. |
| 2609 | */ |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 2610 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2611 | nr_txbds = frags + 2; |
| 2612 | else |
| 2613 | nr_txbds = frags + 1; |
| 2614 | |
| 2615 | lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2616 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2617 | lstatus = be32_to_cpu(lbdp->lstatus); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2618 | |
| 2619 | /* Only clean completed frames */ |
| 2620 | if ((lstatus & BD_LFLAG(TXBD_READY)) && |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2621 | (lstatus & BD_LENGTH_MASK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | break; |
| 2623 | |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 2624 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2625 | next = next_txbd(bdp, base, tx_ring_size); |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2626 | buflen = be16_to_cpu(next->length) + |
| 2627 | GMAC_FCB_LEN + GMAC_TXPAL_LEN; |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2628 | } else |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2629 | buflen = be16_to_cpu(bdp->length); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2630 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2631 | dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr), |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2632 | buflen, DMA_TO_DEVICE); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2633 | |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 2634 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2635 | struct skb_shared_hwtstamps shhwtstamps; |
| 2636 | u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7); |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2637 | |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2638 | memset(&shhwtstamps, 0, sizeof(shhwtstamps)); |
| 2639 | shhwtstamps.hwtstamp = ns_to_ktime(*ns); |
Manfred Rudigier | 9c4886e | 2012-01-09 23:26:51 +0000 | [diff] [blame] | 2640 | skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2641 | skb_tstamp_tx(skb, &shhwtstamps); |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2642 | gfar_clear_txbd_status(bdp); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2643 | bdp = next; |
| 2644 | } |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2645 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2646 | gfar_clear_txbd_status(bdp); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2647 | bdp = next_txbd(bdp, base, tx_ring_size); |
| 2648 | |
| 2649 | for (i = 0; i < frags; i++) { |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2650 | dma_unmap_page(priv->dev, be32_to_cpu(bdp->bufPtr), |
| 2651 | be16_to_cpu(bdp->length), |
| 2652 | DMA_TO_DEVICE); |
| 2653 | gfar_clear_txbd_status(bdp); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2654 | bdp = next_txbd(bdp, base, tx_ring_size); |
| 2655 | } |
| 2656 | |
Claudiu Manoil | 50ad076 | 2013-08-30 15:01:15 +0300 | [diff] [blame] | 2657 | bytes_sent += GFAR_CB(skb)->bytes_sent; |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2658 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 2659 | dev_kfree_skb_any(skb); |
Andy Fleming | 0fd56bb | 2009-02-04 16:43:16 -0800 | [diff] [blame] | 2660 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2661 | tx_queue->tx_skbuff[skb_dirtytx] = NULL; |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2662 | |
| 2663 | skb_dirtytx = (skb_dirtytx + 1) & |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2664 | TX_RING_MOD_MASK(tx_ring_size); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2665 | |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 2666 | howmany++; |
Claudiu Manoil | bc60228 | 2015-05-06 18:07:29 +0300 | [diff] [blame] | 2667 | spin_lock(&tx_queue->txlock); |
Manfred Rudigier | f0ee7ac | 2010-04-08 23:10:35 +0000 | [diff] [blame] | 2668 | tx_queue->num_txbdfree += nr_txbds; |
Claudiu Manoil | bc60228 | 2015-05-06 18:07:29 +0300 | [diff] [blame] | 2669 | spin_unlock(&tx_queue->txlock); |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2672 | /* If we freed a buffer, we can restart transmission, if necessary */ |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 2673 | if (tx_queue->num_txbdfree && |
| 2674 | netif_tx_queue_stopped(txq) && |
| 2675 | !(test_bit(GFAR_DOWN, &priv->state))) |
| 2676 | netif_wake_subqueue(priv->ndev, tqi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 2678 | /* Update dirty indicators */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2679 | tx_queue->skb_dirtytx = skb_dirtytx; |
| 2680 | tx_queue->dirty_tx = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | |
Paul Gortmaker | d8a0f1b | 2012-01-06 13:51:03 -0500 | [diff] [blame] | 2682 | netdev_tx_completed_queue(txq, howmany, bytes_sent); |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 2683 | } |
| 2684 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2685 | static struct sk_buff *gfar_new_skb(struct net_device *ndev, |
| 2686 | dma_addr_t *bufaddr) |
Eran Liberty | acbc0f0 | 2010-07-07 15:54:54 -0700 | [diff] [blame] | 2687 | { |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2688 | struct gfar_private *priv = netdev_priv(ndev); |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 2689 | struct sk_buff *skb; |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2690 | dma_addr_t addr; |
Eran Liberty | acbc0f0 | 2010-07-07 15:54:54 -0700 | [diff] [blame] | 2691 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2692 | skb = netdev_alloc_skb(ndev, priv->rx_buffer_size + RXBUF_ALIGNMENT); |
Eran Liberty | acbc0f0 | 2010-07-07 15:54:54 -0700 | [diff] [blame] | 2693 | if (!skb) |
| 2694 | return NULL; |
| 2695 | |
| 2696 | gfar_align_skb(skb); |
| 2697 | |
Kevin Hao | 0a4b5a2 | 2014-12-11 14:08:41 +0800 | [diff] [blame] | 2698 | addr = dma_map_single(priv->dev, skb->data, |
| 2699 | priv->rx_buffer_size, DMA_FROM_DEVICE); |
| 2700 | if (unlikely(dma_mapping_error(priv->dev, addr))) { |
| 2701 | dev_kfree_skb_any(skb); |
| 2702 | return NULL; |
| 2703 | } |
| 2704 | |
| 2705 | *bufaddr = addr; |
| 2706 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2709 | static void gfar_rx_alloc_err(struct gfar_priv_rx_q *rx_queue) |
| 2710 | { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2711 | struct gfar_private *priv = netdev_priv(rx_queue->ndev); |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2712 | struct gfar_extra_stats *estats = &priv->extra_stats; |
| 2713 | |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2714 | netdev_err(rx_queue->ndev, "Can't alloc RX buffers\n"); |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2715 | atomic64_inc(&estats->rx_alloc_err); |
| 2716 | } |
| 2717 | |
| 2718 | static void gfar_alloc_rx_buffs(struct gfar_priv_rx_q *rx_queue, |
| 2719 | int alloc_cnt) |
| 2720 | { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2721 | struct net_device *ndev = rx_queue->ndev; |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2722 | struct rxbd8 *bdp, *base; |
| 2723 | dma_addr_t bufaddr; |
| 2724 | int i; |
| 2725 | |
| 2726 | i = rx_queue->next_to_use; |
| 2727 | base = rx_queue->rx_bd_base; |
| 2728 | bdp = &rx_queue->rx_bd_base[i]; |
| 2729 | |
| 2730 | while (alloc_cnt--) { |
| 2731 | struct sk_buff *skb = rx_queue->rx_skbuff[i]; |
| 2732 | |
| 2733 | if (likely(!skb)) { |
| 2734 | skb = gfar_new_skb(ndev, &bufaddr); |
| 2735 | if (unlikely(!skb)) { |
| 2736 | gfar_rx_alloc_err(rx_queue); |
| 2737 | break; |
| 2738 | } |
| 2739 | } else { /* restore from sleep state */ |
| 2740 | bufaddr = be32_to_cpu(bdp->bufPtr); |
| 2741 | } |
| 2742 | |
| 2743 | rx_queue->rx_skbuff[i] = skb; |
| 2744 | |
| 2745 | /* Setup the new RxBD */ |
| 2746 | gfar_init_rxbdp(rx_queue, bdp, bufaddr); |
| 2747 | |
| 2748 | /* Update to the next pointer */ |
| 2749 | bdp = next_bd(bdp, base, rx_queue->rx_ring_size); |
| 2750 | |
| 2751 | if (unlikely(++i == rx_queue->rx_ring_size)) |
| 2752 | i = 0; |
| 2753 | } |
| 2754 | |
| 2755 | rx_queue->next_to_use = i; |
| 2756 | } |
| 2757 | |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2758 | static void count_errors(u32 lstatus, struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2760 | struct gfar_private *priv = netdev_priv(ndev); |
| 2761 | struct net_device_stats *stats = &ndev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | struct gfar_extra_stats *estats = &priv->extra_stats; |
| 2763 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2764 | /* If the packet was truncated, none of the other errors matter */ |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2765 | if (lstatus & BD_LFLAG(RXBD_TRUNCATED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | stats->rx_length_errors++; |
| 2767 | |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2768 | atomic64_inc(&estats->rx_trunc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
| 2770 | return; |
| 2771 | } |
| 2772 | /* Count the errors, if there were any */ |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2773 | if (lstatus & BD_LFLAG(RXBD_LARGE | RXBD_SHORT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | stats->rx_length_errors++; |
| 2775 | |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2776 | if (lstatus & BD_LFLAG(RXBD_LARGE)) |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2777 | atomic64_inc(&estats->rx_large); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | else |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2779 | atomic64_inc(&estats->rx_short); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | } |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2781 | if (lstatus & BD_LFLAG(RXBD_NONOCTET)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | stats->rx_frame_errors++; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2783 | atomic64_inc(&estats->rx_nonoctet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | } |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2785 | if (lstatus & BD_LFLAG(RXBD_CRCERR)) { |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2786 | atomic64_inc(&estats->rx_crcerr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | stats->rx_crc_errors++; |
| 2788 | } |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2789 | if (lstatus & BD_LFLAG(RXBD_OVERRUN)) { |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2790 | atomic64_inc(&estats->rx_overrun); |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2791 | stats->rx_over_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 2795 | irqreturn_t gfar_receive(int irq, void *grp_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | { |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 2797 | struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id; |
| 2798 | unsigned long flags; |
| 2799 | u32 imask; |
| 2800 | |
| 2801 | if (likely(napi_schedule_prep(&grp->napi_rx))) { |
| 2802 | spin_lock_irqsave(&grp->grplock, flags); |
| 2803 | imask = gfar_read(&grp->regs->imask); |
| 2804 | imask &= IMASK_RX_DISABLED; |
| 2805 | gfar_write(&grp->regs->imask, imask); |
| 2806 | spin_unlock_irqrestore(&grp->grplock, flags); |
| 2807 | __napi_schedule(&grp->napi_rx); |
| 2808 | } else { |
| 2809 | /* Clear IEVENT, so interrupts aren't called again |
| 2810 | * because of the packets that have already arrived. |
| 2811 | */ |
| 2812 | gfar_write(&grp->regs->ievent, IEVENT_RX_MASK); |
| 2813 | } |
| 2814 | |
| 2815 | return IRQ_HANDLED; |
| 2816 | } |
| 2817 | |
| 2818 | /* Interrupt Handler for Transmit complete */ |
| 2819 | static irqreturn_t gfar_transmit(int irq, void *grp_id) |
| 2820 | { |
| 2821 | struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id; |
| 2822 | unsigned long flags; |
| 2823 | u32 imask; |
| 2824 | |
| 2825 | if (likely(napi_schedule_prep(&grp->napi_tx))) { |
| 2826 | spin_lock_irqsave(&grp->grplock, flags); |
| 2827 | imask = gfar_read(&grp->regs->imask); |
| 2828 | imask &= IMASK_TX_DISABLED; |
| 2829 | gfar_write(&grp->regs->imask, imask); |
| 2830 | spin_unlock_irqrestore(&grp->grplock, flags); |
| 2831 | __napi_schedule(&grp->napi_tx); |
| 2832 | } else { |
| 2833 | /* Clear IEVENT, so interrupts aren't called again |
| 2834 | * because of the packets that have already arrived. |
| 2835 | */ |
| 2836 | gfar_write(&grp->regs->ievent, IEVENT_TX_MASK); |
| 2837 | } |
| 2838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | return IRQ_HANDLED; |
| 2840 | } |
| 2841 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2842 | static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb) |
| 2843 | { |
| 2844 | /* If valid headers were found, and valid sums |
| 2845 | * were verified, then we tell the kernel that no |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2846 | * checksumming is necessary. Otherwise, it is [FIXME] |
| 2847 | */ |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2848 | if ((be16_to_cpu(fcb->flags) & RXFCB_CSUM_MASK) == |
| 2849 | (RXFCB_CIP | RXFCB_CTU)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2850 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2851 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 2852 | skb_checksum_none_assert(skb); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2853 | } |
| 2854 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2855 | /* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */ |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2856 | static void gfar_process_frame(struct net_device *ndev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2858 | struct gfar_private *priv = netdev_priv(ndev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2859 | struct rxfcb *fcb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2861 | /* fcb is at the beginning if exists */ |
| 2862 | fcb = (struct rxfcb *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 2864 | /* Remove the FCB from the skb |
| 2865 | * Remove the padded bytes, if there are any |
| 2866 | */ |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2867 | if (priv->uses_rxfcb) |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2868 | skb_pull(skb, GMAC_FCB_LEN); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2869 | |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 2870 | /* Get receive timestamp from the skb */ |
| 2871 | if (priv->hwts_rx_en) { |
| 2872 | struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); |
| 2873 | u64 *ns = (u64 *) skb->data; |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2874 | |
Manfred Rudigier | cc772ab | 2010-04-08 23:10:03 +0000 | [diff] [blame] | 2875 | memset(shhwtstamps, 0, sizeof(*shhwtstamps)); |
| 2876 | shhwtstamps->hwtstamp = ns_to_ktime(*ns); |
| 2877 | } |
| 2878 | |
| 2879 | if (priv->padding) |
| 2880 | skb_pull(skb, priv->padding); |
| 2881 | |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2882 | if (ndev->features & NETIF_F_RXCSUM) |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2883 | gfar_rx_checksum(skb, fcb); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2884 | |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2885 | /* Tell the skb what kind of packet this is */ |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2886 | skb->protocol = eth_type_trans(skb, ndev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 2887 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2888 | /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here. |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2889 | * Even if vlan rx accel is disabled, on some chips |
| 2890 | * RXFCB_VLN is pseudo randomly set. |
| 2891 | */ |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2892 | if (ndev->features & NETIF_F_HW_VLAN_CTAG_RX && |
Claudiu Manoil | 26eb937 | 2015-03-13 10:36:29 +0200 | [diff] [blame] | 2893 | be16_to_cpu(fcb->flags) & RXFCB_VLN) |
| 2894 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 2895 | be16_to_cpu(fcb->vlctl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | /* gfar_clean_rx_ring() -- Processes each frame in the rx ring |
Jan Ceuleers | 2281a0f | 2012-06-05 03:42:11 +0000 | [diff] [blame] | 2899 | * until the budget/quota has been reached. Returns the number |
| 2900 | * of frames handled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2902 | int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2904 | struct net_device *ndev = rx_queue->ndev; |
Andy Fleming | 31de198 | 2008-12-16 15:33:40 -0800 | [diff] [blame] | 2905 | struct rxbd8 *bdp, *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | struct sk_buff *skb; |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2907 | int i, howmany = 0; |
| 2908 | int cleaned_cnt = gfar_rxbd_unused(rx_queue); |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2909 | struct gfar_private *priv = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | |
| 2911 | /* Get the first full descriptor */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 2912 | base = rx_queue->rx_bd_base; |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2913 | i = rx_queue->next_to_clean; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2915 | while (rx_work_limit--) { |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2916 | u32 lstatus; |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2917 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2918 | if (cleaned_cnt >= GFAR_RX_BUFF_ALLOC) { |
| 2919 | gfar_alloc_rx_buffs(rx_queue, cleaned_cnt); |
| 2920 | cleaned_cnt = 0; |
| 2921 | } |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2922 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2923 | bdp = &rx_queue->rx_bd_base[i]; |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2924 | lstatus = be32_to_cpu(bdp->lstatus); |
| 2925 | if (lstatus & BD_LFLAG(RXBD_EMPTY)) |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2926 | break; |
| 2927 | |
| 2928 | /* order rx buffer descriptor reads */ |
Scott Wood | 3b6330c | 2007-05-16 15:06:59 -0500 | [diff] [blame] | 2929 | rmb(); |
Andy Fleming | 815b97c | 2008-04-22 17:18:29 -0500 | [diff] [blame] | 2930 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2931 | /* fetch next to clean buffer from the ring */ |
| 2932 | skb = rx_queue->rx_skbuff[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2934 | dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr), |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 2935 | priv->rx_buffer_size, DMA_FROM_DEVICE); |
Andy Fleming | 8118305 | 2008-11-12 10:07:11 -0600 | [diff] [blame] | 2936 | |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2937 | if (unlikely(!(lstatus & BD_LFLAG(RXBD_ERR)) && |
| 2938 | (lstatus & BD_LENGTH_MASK) > priv->rx_buffer_size)) |
| 2939 | lstatus |= BD_LFLAG(RXBD_LARGE); |
Anton Vorontsov | 63b88b9 | 2010-06-11 10:51:03 +0000 | [diff] [blame] | 2940 | |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2941 | if (unlikely(!(lstatus & BD_LFLAG(RXBD_LAST)) || |
| 2942 | (lstatus & BD_LFLAG(RXBD_ERR)))) { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2943 | count_errors(lstatus, ndev); |
Andy Fleming | 815b97c | 2008-04-22 17:18:29 -0500 | [diff] [blame] | 2944 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2945 | /* discard faulty buffer */ |
| 2946 | dev_kfree_skb(skb); |
| 2947 | |
Andy Fleming | 815b97c | 2008-04-22 17:18:29 -0500 | [diff] [blame] | 2948 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | /* Increment the number of packets */ |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 2950 | rx_queue->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | howmany++; |
| 2952 | |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2953 | if (likely(skb)) { |
Claudiu Manoil | f966082 | 2015-07-13 16:22:04 +0300 | [diff] [blame] | 2954 | int pkt_len = (lstatus & BD_LENGTH_MASK) - |
Claudiu Manoil | a7312d5 | 2015-03-13 10:36:28 +0200 | [diff] [blame] | 2955 | ETH_FCS_LEN; |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2956 | /* Remove the FCS from the packet length */ |
| 2957 | skb_put(skb, pkt_len); |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 2958 | rx_queue->stats.rx_bytes += pkt_len; |
Sandeep Gopalpet | f74dac0 | 2009-12-24 03:13:06 +0000 | [diff] [blame] | 2959 | skb_record_rx_queue(skb, rx_queue->qindex); |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2960 | gfar_process_frame(ndev, skb); |
| 2961 | |
| 2962 | /* Send the packet up the stack */ |
| 2963 | napi_gro_receive(&rx_queue->grp->napi_rx, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2965 | } else { |
Claudiu Manoil | f23223f | 2015-07-13 16:22:05 +0300 | [diff] [blame^] | 2966 | netif_warn(priv, rx_err, ndev, "Missing skb!\n"); |
Sandeep Gopalpet | a7f3804 | 2009-12-16 01:15:07 +0000 | [diff] [blame] | 2967 | rx_queue->stats.rx_dropped++; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 2968 | atomic64_inc(&priv->extra_stats.rx_skbmissing); |
Dai Haruki | 2c2db48 | 2008-12-16 15:31:15 -0800 | [diff] [blame] | 2969 | } |
| 2970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2973 | rx_queue->rx_skbuff[i] = NULL; |
| 2974 | cleaned_cnt++; |
| 2975 | if (unlikely(++i == rx_queue->rx_ring_size)) |
| 2976 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 2979 | rx_queue->next_to_clean = i; |
| 2980 | |
| 2981 | if (cleaned_cnt) |
| 2982 | gfar_alloc_rx_buffs(rx_queue, cleaned_cnt); |
| 2983 | |
| 2984 | /* Update Last Free RxBD pointer for LFC */ |
| 2985 | if (unlikely(priv->tx_actual_en)) { |
| 2986 | bdp = gfar_rxbd_lastfree(rx_queue); |
| 2987 | gfar_write(rx_queue->rfbptr, (u32)bdp); |
| 2988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | return howmany; |
| 2991 | } |
| 2992 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 2993 | static int gfar_poll_rx_sq(struct napi_struct *napi, int budget) |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 2994 | { |
| 2995 | struct gfar_priv_grp *gfargrp = |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 2996 | container_of(napi, struct gfar_priv_grp, napi_rx); |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 2997 | struct gfar __iomem *regs = gfargrp->regs; |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 2998 | struct gfar_priv_rx_q *rx_queue = gfargrp->rx_queue; |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 2999 | int work_done = 0; |
| 3000 | |
| 3001 | /* Clear IEVENT, so interrupts aren't called again |
| 3002 | * because of the packets that have already arrived |
| 3003 | */ |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3004 | gfar_write(®s->ievent, IEVENT_RX_MASK); |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 3005 | |
| 3006 | work_done = gfar_clean_rx_ring(rx_queue, budget); |
| 3007 | |
| 3008 | if (work_done < budget) { |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3009 | u32 imask; |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 3010 | napi_complete(napi); |
| 3011 | /* Clear the halt bit in RSTAT */ |
| 3012 | gfar_write(®s->rstat, gfargrp->rstat); |
| 3013 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3014 | spin_lock_irq(&gfargrp->grplock); |
| 3015 | imask = gfar_read(®s->imask); |
| 3016 | imask |= IMASK_RX_DEFAULT; |
| 3017 | gfar_write(®s->imask, imask); |
| 3018 | spin_unlock_irq(&gfargrp->grplock); |
Claudiu Manoil | 5eaedf3 | 2013-06-10 20:19:48 +0300 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | return work_done; |
| 3022 | } |
| 3023 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3024 | static int gfar_poll_tx_sq(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | { |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 3026 | struct gfar_priv_grp *gfargrp = |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3027 | container_of(napi, struct gfar_priv_grp, napi_tx); |
| 3028 | struct gfar __iomem *regs = gfargrp->regs; |
Claudiu Manoil | 71ff9e3 | 2014-03-07 14:42:46 +0200 | [diff] [blame] | 3029 | struct gfar_priv_tx_q *tx_queue = gfargrp->tx_queue; |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3030 | u32 imask; |
| 3031 | |
| 3032 | /* Clear IEVENT, so interrupts aren't called again |
| 3033 | * because of the packets that have already arrived |
| 3034 | */ |
| 3035 | gfar_write(®s->ievent, IEVENT_TX_MASK); |
| 3036 | |
| 3037 | /* run Tx cleanup to completion */ |
| 3038 | if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx]) |
| 3039 | gfar_clean_tx_ring(tx_queue); |
| 3040 | |
| 3041 | napi_complete(napi); |
| 3042 | |
| 3043 | spin_lock_irq(&gfargrp->grplock); |
| 3044 | imask = gfar_read(®s->imask); |
| 3045 | imask |= IMASK_TX_DEFAULT; |
| 3046 | gfar_write(®s->imask, imask); |
| 3047 | spin_unlock_irq(&gfargrp->grplock); |
| 3048 | |
| 3049 | return 0; |
| 3050 | } |
| 3051 | |
| 3052 | static int gfar_poll_rx(struct napi_struct *napi, int budget) |
| 3053 | { |
| 3054 | struct gfar_priv_grp *gfargrp = |
| 3055 | container_of(napi, struct gfar_priv_grp, napi_rx); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 3056 | struct gfar_private *priv = gfargrp->priv; |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3057 | struct gfar __iomem *regs = gfargrp->regs; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 3058 | struct gfar_priv_rx_q *rx_queue = NULL; |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3059 | int work_done = 0, work_done_per_q = 0; |
Claudiu Manoil | 39c0a0d | 2013-03-21 03:12:13 +0000 | [diff] [blame] | 3060 | int i, budget_per_q = 0; |
Claudiu Manoil | 6be5ed3 | 2013-03-19 07:40:03 +0000 | [diff] [blame] | 3061 | unsigned long rstat_rxf; |
| 3062 | int num_act_queues; |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 3063 | |
Dai Haruki | 8c7396a | 2008-12-17 16:52:00 -0800 | [diff] [blame] | 3064 | /* Clear IEVENT, so interrupts aren't called again |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3065 | * because of the packets that have already arrived |
| 3066 | */ |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3067 | gfar_write(®s->ievent, IEVENT_RX_MASK); |
Dai Haruki | 8c7396a | 2008-12-17 16:52:00 -0800 | [diff] [blame] | 3068 | |
Claudiu Manoil | 6be5ed3 | 2013-03-19 07:40:03 +0000 | [diff] [blame] | 3069 | rstat_rxf = gfar_read(®s->rstat) & RSTAT_RXF_MASK; |
| 3070 | |
| 3071 | num_act_queues = bitmap_weight(&rstat_rxf, MAX_RX_QS); |
| 3072 | if (num_act_queues) |
| 3073 | budget_per_q = budget/num_act_queues; |
| 3074 | |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3075 | for_each_set_bit(i, &gfargrp->rx_bit_map, priv->num_rx_queues) { |
| 3076 | /* skip queue if not active */ |
| 3077 | if (!(rstat_rxf & (RSTAT_CLEAR_RXF0 >> i))) |
| 3078 | continue; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 3079 | |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3080 | rx_queue = priv->rx_queue[i]; |
| 3081 | work_done_per_q = |
| 3082 | gfar_clean_rx_ring(rx_queue, budget_per_q); |
| 3083 | work_done += work_done_per_q; |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3084 | |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3085 | /* finished processing this queue */ |
| 3086 | if (work_done_per_q < budget_per_q) { |
| 3087 | /* clear active queue hw indication */ |
| 3088 | gfar_write(®s->rstat, |
| 3089 | RSTAT_CLEAR_RXF0 >> i); |
| 3090 | num_act_queues--; |
Claudiu Manoil | 6be5ed3 | 2013-03-19 07:40:03 +0000 | [diff] [blame] | 3091 | |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3092 | if (!num_act_queues) |
| 3093 | break; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 3094 | } |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3095 | } |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3096 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3097 | if (!num_act_queues) { |
| 3098 | u32 imask; |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3099 | napi_complete(napi); |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3100 | |
Claudiu Manoil | 3ba405d | 2013-10-14 17:05:09 +0300 | [diff] [blame] | 3101 | /* Clear the halt bit in RSTAT */ |
| 3102 | gfar_write(®s->rstat, gfargrp->rstat); |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3103 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3104 | spin_lock_irq(&gfargrp->grplock); |
| 3105 | imask = gfar_read(®s->imask); |
| 3106 | imask |= IMASK_RX_DEFAULT; |
| 3107 | gfar_write(®s->imask, imask); |
| 3108 | spin_unlock_irq(&gfargrp->grplock); |
Dai Haruki | d080cd6 | 2008-04-09 19:37:51 -0500 | [diff] [blame] | 3109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | |
Claudiu Manoil | c233cf40 | 2013-03-19 07:40:02 +0000 | [diff] [blame] | 3111 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | |
Claudiu Manoil | aeb12c5 | 2014-03-07 14:42:45 +0200 | [diff] [blame] | 3114 | static int gfar_poll_tx(struct napi_struct *napi, int budget) |
| 3115 | { |
| 3116 | struct gfar_priv_grp *gfargrp = |
| 3117 | container_of(napi, struct gfar_priv_grp, napi_tx); |
| 3118 | struct gfar_private *priv = gfargrp->priv; |
| 3119 | struct gfar __iomem *regs = gfargrp->regs; |
| 3120 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 3121 | int has_tx_work = 0; |
| 3122 | int i; |
| 3123 | |
| 3124 | /* Clear IEVENT, so interrupts aren't called again |
| 3125 | * because of the packets that have already arrived |
| 3126 | */ |
| 3127 | gfar_write(®s->ievent, IEVENT_TX_MASK); |
| 3128 | |
| 3129 | for_each_set_bit(i, &gfargrp->tx_bit_map, priv->num_tx_queues) { |
| 3130 | tx_queue = priv->tx_queue[i]; |
| 3131 | /* run Tx cleanup to completion */ |
| 3132 | if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx]) { |
| 3133 | gfar_clean_tx_ring(tx_queue); |
| 3134 | has_tx_work = 1; |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | if (!has_tx_work) { |
| 3139 | u32 imask; |
| 3140 | napi_complete(napi); |
| 3141 | |
| 3142 | spin_lock_irq(&gfargrp->grplock); |
| 3143 | imask = gfar_read(®s->imask); |
| 3144 | imask |= IMASK_TX_DEFAULT; |
| 3145 | gfar_write(®s->imask, imask); |
| 3146 | spin_unlock_irq(&gfargrp->grplock); |
| 3147 | } |
| 3148 | |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
| 3152 | |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 3153 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3154 | /* Polling 'interrupt' - used by things like netconsole to send skbs |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 3155 | * without having to re-enable interrupts. It's not called while |
| 3156 | * the interrupt routine is executing. |
| 3157 | */ |
| 3158 | static void gfar_netpoll(struct net_device *dev) |
| 3159 | { |
| 3160 | struct gfar_private *priv = netdev_priv(dev); |
Jan Ceuleers | 3a2e16c | 2012-06-05 03:42:14 +0000 | [diff] [blame] | 3161 | int i; |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 3162 | |
| 3163 | /* If the device has multiple interrupts, run tx/rx */ |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 3164 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3165 | for (i = 0; i < priv->num_grps; i++) { |
Paul Gortmaker | 62ed839 | 2013-02-24 05:38:31 +0000 | [diff] [blame] | 3166 | struct gfar_priv_grp *grp = &priv->gfargrp[i]; |
| 3167 | |
| 3168 | disable_irq(gfar_irq(grp, TX)->irq); |
| 3169 | disable_irq(gfar_irq(grp, RX)->irq); |
| 3170 | disable_irq(gfar_irq(grp, ER)->irq); |
| 3171 | gfar_interrupt(gfar_irq(grp, TX)->irq, grp); |
| 3172 | enable_irq(gfar_irq(grp, ER)->irq); |
| 3173 | enable_irq(gfar_irq(grp, RX)->irq); |
| 3174 | enable_irq(gfar_irq(grp, TX)->irq); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3175 | } |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 3176 | } else { |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3177 | for (i = 0; i < priv->num_grps; i++) { |
Paul Gortmaker | 62ed839 | 2013-02-24 05:38:31 +0000 | [diff] [blame] | 3178 | struct gfar_priv_grp *grp = &priv->gfargrp[i]; |
| 3179 | |
| 3180 | disable_irq(gfar_irq(grp, TX)->irq); |
| 3181 | gfar_interrupt(gfar_irq(grp, TX)->irq, grp); |
| 3182 | enable_irq(gfar_irq(grp, TX)->irq); |
Anton Vorontsov | 43de004 | 2009-12-09 02:52:19 -0800 | [diff] [blame] | 3183 | } |
Vitaly Wool | f2d71c2 | 2006-11-07 13:27:02 +0300 | [diff] [blame] | 3184 | } |
| 3185 | } |
| 3186 | #endif |
| 3187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | /* The interrupt handler for devices with one interrupt */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3189 | static irqreturn_t gfar_interrupt(int irq, void *grp_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | { |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3191 | struct gfar_priv_grp *gfargrp = grp_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | |
| 3193 | /* Save ievent for future reference */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3194 | u32 events = gfar_read(&gfargrp->regs->ievent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | /* Check for reception */ |
Sergei Shtylyov | 538cc7e | 2007-02-15 17:56:01 +0400 | [diff] [blame] | 3197 | if (events & IEVENT_RX_MASK) |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3198 | gfar_receive(irq, grp_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | |
| 3200 | /* Check for transmit completion */ |
Sergei Shtylyov | 538cc7e | 2007-02-15 17:56:01 +0400 | [diff] [blame] | 3201 | if (events & IEVENT_TX_MASK) |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3202 | gfar_transmit(irq, grp_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
Sergei Shtylyov | 538cc7e | 2007-02-15 17:56:01 +0400 | [diff] [blame] | 3204 | /* Check for errors */ |
| 3205 | if (events & IEVENT_ERR_MASK) |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3206 | gfar_error(irq, grp_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | |
| 3208 | return IRQ_HANDLED; |
| 3209 | } |
| 3210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | /* Called every time the controller might need to be made |
| 3212 | * aware of new link state. The PHY code conveys this |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 3213 | * information through variables in the phydev structure, and this |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | * function converts those variables into the appropriate |
| 3215 | * register values, and can bring down the device if needed. |
| 3216 | */ |
| 3217 | static void adjust_link(struct net_device *dev) |
| 3218 | { |
| 3219 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 3220 | struct phy_device *phydev = priv->phydev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3222 | if (unlikely(phydev->link != priv->oldlink || |
Guenter Roeck | 0ae93b2 | 2015-03-02 12:03:27 -0800 | [diff] [blame] | 3223 | (phydev->link && (phydev->duplex != priv->oldduplex || |
| 3224 | phydev->speed != priv->oldspeed)))) |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3225 | gfar_update_link_state(priv); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 3226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | |
| 3228 | /* Update the hash table based on the current list of multicast |
| 3229 | * addresses we subscribe to. Also, change the promiscuity of |
| 3230 | * the device based on the flags (this function is called |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3231 | * whenever dev->flags is changed |
| 3232 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | static void gfar_set_multi(struct net_device *dev) |
| 3234 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3235 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3237 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | u32 tempval; |
| 3239 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 3240 | if (dev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | /* Set RCTRL to PROM */ |
| 3242 | tempval = gfar_read(®s->rctrl); |
| 3243 | tempval |= RCTRL_PROM; |
| 3244 | gfar_write(®s->rctrl, tempval); |
| 3245 | } else { |
| 3246 | /* Set RCTRL to not PROM */ |
| 3247 | tempval = gfar_read(®s->rctrl); |
| 3248 | tempval &= ~(RCTRL_PROM); |
| 3249 | gfar_write(®s->rctrl, tempval); |
| 3250 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3251 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 3252 | if (dev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | /* Set the hash to rx all multicast frames */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3254 | gfar_write(®s->igaddr0, 0xffffffff); |
| 3255 | gfar_write(®s->igaddr1, 0xffffffff); |
| 3256 | gfar_write(®s->igaddr2, 0xffffffff); |
| 3257 | gfar_write(®s->igaddr3, 0xffffffff); |
| 3258 | gfar_write(®s->igaddr4, 0xffffffff); |
| 3259 | gfar_write(®s->igaddr5, 0xffffffff); |
| 3260 | gfar_write(®s->igaddr6, 0xffffffff); |
| 3261 | gfar_write(®s->igaddr7, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | gfar_write(®s->gaddr0, 0xffffffff); |
| 3263 | gfar_write(®s->gaddr1, 0xffffffff); |
| 3264 | gfar_write(®s->gaddr2, 0xffffffff); |
| 3265 | gfar_write(®s->gaddr3, 0xffffffff); |
| 3266 | gfar_write(®s->gaddr4, 0xffffffff); |
| 3267 | gfar_write(®s->gaddr5, 0xffffffff); |
| 3268 | gfar_write(®s->gaddr6, 0xffffffff); |
| 3269 | gfar_write(®s->gaddr7, 0xffffffff); |
| 3270 | } else { |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3271 | int em_num; |
| 3272 | int idx; |
| 3273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | /* zero out the hash */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3275 | gfar_write(®s->igaddr0, 0x0); |
| 3276 | gfar_write(®s->igaddr1, 0x0); |
| 3277 | gfar_write(®s->igaddr2, 0x0); |
| 3278 | gfar_write(®s->igaddr3, 0x0); |
| 3279 | gfar_write(®s->igaddr4, 0x0); |
| 3280 | gfar_write(®s->igaddr5, 0x0); |
| 3281 | gfar_write(®s->igaddr6, 0x0); |
| 3282 | gfar_write(®s->igaddr7, 0x0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | gfar_write(®s->gaddr0, 0x0); |
| 3284 | gfar_write(®s->gaddr1, 0x0); |
| 3285 | gfar_write(®s->gaddr2, 0x0); |
| 3286 | gfar_write(®s->gaddr3, 0x0); |
| 3287 | gfar_write(®s->gaddr4, 0x0); |
| 3288 | gfar_write(®s->gaddr5, 0x0); |
| 3289 | gfar_write(®s->gaddr6, 0x0); |
| 3290 | gfar_write(®s->gaddr7, 0x0); |
| 3291 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3292 | /* If we have extended hash tables, we need to |
| 3293 | * clear the exact match registers to prepare for |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3294 | * setting them |
| 3295 | */ |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3296 | if (priv->extended_hash) { |
| 3297 | em_num = GFAR_EM_NUM + 1; |
| 3298 | gfar_clear_exact_match(dev); |
| 3299 | idx = 1; |
| 3300 | } else { |
| 3301 | idx = 0; |
| 3302 | em_num = 0; |
| 3303 | } |
| 3304 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3305 | if (netdev_mc_empty(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | return; |
| 3307 | |
| 3308 | /* Parse the list, and set the appropriate bits */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3309 | netdev_for_each_mc_addr(ha, dev) { |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3310 | if (idx < em_num) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3311 | gfar_set_mac_for_addr(dev, idx, ha->addr); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3312 | idx++; |
| 3313 | } else |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3314 | gfar_set_hash_for_addr(dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
| 3316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3319 | |
| 3320 | /* Clears each of the exact match registers to zero, so they |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3321 | * don't interfere with normal reception |
| 3322 | */ |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3323 | static void gfar_clear_exact_match(struct net_device *dev) |
| 3324 | { |
| 3325 | int idx; |
Joe Perches | 6a3c910c | 2011-11-16 09:38:02 +0000 | [diff] [blame] | 3326 | static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0}; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3327 | |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 3328 | for (idx = 1; idx < GFAR_EM_NUM + 1; idx++) |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3329 | gfar_set_mac_for_addr(dev, idx, zero_arr); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3330 | } |
| 3331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | /* Set the appropriate hash bit for the given addr */ |
| 3333 | /* The algorithm works like so: |
| 3334 | * 1) Take the Destination Address (ie the multicast address), and |
| 3335 | * do a CRC on it (little endian), and reverse the bits of the |
| 3336 | * result. |
| 3337 | * 2) Use the 8 most significant bits as a hash into a 256-entry |
| 3338 | * table. The table is controlled through 8 32-bit registers: |
| 3339 | * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is |
| 3340 | * gaddr7. This means that the 3 most significant bits in the |
| 3341 | * hash index which gaddr register to use, and the 5 other bits |
| 3342 | * indicate which bit (assuming an IBM numbering scheme, which |
| 3343 | * for PowerPC (tm) is usually the case) in the register holds |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3344 | * the entry. |
| 3345 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr) |
| 3347 | { |
| 3348 | u32 tempval; |
| 3349 | struct gfar_private *priv = netdev_priv(dev); |
Joe Perches | 6a3c910c | 2011-11-16 09:38:02 +0000 | [diff] [blame] | 3350 | u32 result = ether_crc(ETH_ALEN, addr); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3351 | int width = priv->hash_width; |
| 3352 | u8 whichbit = (result >> (32 - width)) & 0x1f; |
| 3353 | u8 whichreg = result >> (32 - width + 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | u32 value = (1 << (31-whichbit)); |
| 3355 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3356 | tempval = gfar_read(priv->hash_regs[whichreg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | tempval |= value; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3358 | gfar_write(priv->hash_regs[whichreg], tempval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3361 | |
| 3362 | /* There are multiple MAC Address register pairs on some controllers |
| 3363 | * This function sets the numth pair to a given address |
| 3364 | */ |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3365 | static void gfar_set_mac_for_addr(struct net_device *dev, int num, |
| 3366 | const u8 *addr) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3367 | { |
| 3368 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3369 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3370 | u32 tempval; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3371 | u32 __iomem *macptr = ®s->macstnaddr1; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3372 | |
| 3373 | macptr += num*2; |
| 3374 | |
Claudiu Manoil | 83bfc3c | 2014-10-07 10:44:33 +0300 | [diff] [blame] | 3375 | /* For a station address of 0x12345678ABCD in transmission |
| 3376 | * order (BE), MACnADDR1 is set to 0xCDAB7856 and |
| 3377 | * MACnADDR2 is set to 0x34120000. |
Jan Ceuleers | 0977f81 | 2012-06-05 03:42:12 +0000 | [diff] [blame] | 3378 | */ |
Claudiu Manoil | 83bfc3c | 2014-10-07 10:44:33 +0300 | [diff] [blame] | 3379 | tempval = (addr[5] << 24) | (addr[4] << 16) | |
| 3380 | (addr[3] << 8) | addr[2]; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3381 | |
Claudiu Manoil | 83bfc3c | 2014-10-07 10:44:33 +0300 | [diff] [blame] | 3382 | gfar_write(macptr, tempval); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3383 | |
Claudiu Manoil | 83bfc3c | 2014-10-07 10:44:33 +0300 | [diff] [blame] | 3384 | tempval = (addr[1] << 24) | (addr[0] << 16); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 3385 | |
| 3386 | gfar_write(macptr+1, tempval); |
| 3387 | } |
| 3388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | /* GFAR error interrupt handler */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3390 | static irqreturn_t gfar_error(int irq, void *grp_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | { |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3392 | struct gfar_priv_grp *gfargrp = grp_id; |
| 3393 | struct gfar __iomem *regs = gfargrp->regs; |
| 3394 | struct gfar_private *priv= gfargrp->priv; |
| 3395 | struct net_device *dev = priv->ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | |
| 3397 | /* Save ievent for future reference */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3398 | u32 events = gfar_read(®s->ievent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | |
| 3400 | /* Clear IEVENT */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3401 | gfar_write(®s->ievent, events & IEVENT_ERR_MASK); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 3402 | |
| 3403 | /* Magic Packet is not an error. */ |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 3404 | if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 3405 | (events & IEVENT_MAG)) |
| 3406 | events &= ~IEVENT_MAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | |
| 3408 | /* Hmm... */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 3409 | if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv)) |
Jan Ceuleers | bc4598b | 2012-06-05 03:42:13 +0000 | [diff] [blame] | 3410 | netdev_dbg(dev, |
| 3411 | "error interrupt (ievent=0x%08x imask=0x%08x)\n", |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3412 | events, gfar_read(®s->imask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
| 3414 | /* Update the error counters */ |
| 3415 | if (events & IEVENT_TXE) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3416 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
| 3418 | if (events & IEVENT_LC) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3419 | dev->stats.tx_window_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | if (events & IEVENT_CRL) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3421 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | if (events & IEVENT_XFUN) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3423 | netif_dbg(priv, tx_err, dev, |
| 3424 | "TX FIFO underrun, packet dropped\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3425 | dev->stats.tx_dropped++; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 3426 | atomic64_inc(&priv->extra_stats.tx_underrun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | |
Claudiu Manoil | bc60228 | 2015-05-06 18:07:29 +0300 | [diff] [blame] | 3428 | schedule_work(&priv->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | } |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3430 | netif_dbg(priv, tx_err, dev, "Transmit Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | } |
| 3432 | if (events & IEVENT_BSY) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3433 | dev->stats.rx_errors++; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 3434 | atomic64_inc(&priv->extra_stats.rx_bsy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 3436 | gfar_receive(irq, grp_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3438 | netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n", |
| 3439 | gfar_read(®s->rstat)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | } |
| 3441 | if (events & IEVENT_BABR) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 3442 | dev->stats.rx_errors++; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 3443 | atomic64_inc(&priv->extra_stats.rx_babr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3445 | netif_dbg(priv, rx_err, dev, "babbling RX error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | } |
| 3447 | if (events & IEVENT_EBERR) { |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 3448 | atomic64_inc(&priv->extra_stats.eberr); |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3449 | netif_dbg(priv, rx_err, dev, "bus error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | } |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3451 | if (events & IEVENT_RXC) |
| 3452 | netif_dbg(priv, rx_status, dev, "control frame\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | |
| 3454 | if (events & IEVENT_BABT) { |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 3455 | atomic64_inc(&priv->extra_stats.tx_babt); |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 3456 | netif_dbg(priv, tx_err, dev, "babbling TX error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | } |
| 3458 | return IRQ_HANDLED; |
| 3459 | } |
| 3460 | |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3461 | static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv) |
| 3462 | { |
| 3463 | struct phy_device *phydev = priv->phydev; |
| 3464 | u32 val = 0; |
| 3465 | |
| 3466 | if (!phydev->duplex) |
| 3467 | return val; |
| 3468 | |
| 3469 | if (!priv->pause_aneg_en) { |
| 3470 | if (priv->tx_pause_en) |
| 3471 | val |= MACCFG1_TX_FLOW; |
| 3472 | if (priv->rx_pause_en) |
| 3473 | val |= MACCFG1_RX_FLOW; |
| 3474 | } else { |
| 3475 | u16 lcl_adv, rmt_adv; |
| 3476 | u8 flowctrl; |
| 3477 | /* get link partner capabilities */ |
| 3478 | rmt_adv = 0; |
| 3479 | if (phydev->pause) |
| 3480 | rmt_adv = LPA_PAUSE_CAP; |
| 3481 | if (phydev->asym_pause) |
| 3482 | rmt_adv |= LPA_PAUSE_ASYM; |
| 3483 | |
Pavaluca Matei-B46610 | 43ef8d2 | 2014-10-27 10:42:43 +0200 | [diff] [blame] | 3484 | lcl_adv = 0; |
| 3485 | if (phydev->advertising & ADVERTISED_Pause) |
| 3486 | lcl_adv |= ADVERTISE_PAUSE_CAP; |
| 3487 | if (phydev->advertising & ADVERTISED_Asym_Pause) |
| 3488 | lcl_adv |= ADVERTISE_PAUSE_ASYM; |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3489 | |
| 3490 | flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv); |
| 3491 | if (flowctrl & FLOW_CTRL_TX) |
| 3492 | val |= MACCFG1_TX_FLOW; |
| 3493 | if (flowctrl & FLOW_CTRL_RX) |
| 3494 | val |= MACCFG1_RX_FLOW; |
| 3495 | } |
| 3496 | |
| 3497 | return val; |
| 3498 | } |
| 3499 | |
| 3500 | static noinline void gfar_update_link_state(struct gfar_private *priv) |
| 3501 | { |
| 3502 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
| 3503 | struct phy_device *phydev = priv->phydev; |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 3504 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 3505 | int i; |
| 3506 | struct rxbd8 *bdp; |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3507 | |
| 3508 | if (unlikely(test_bit(GFAR_RESETTING, &priv->state))) |
| 3509 | return; |
| 3510 | |
| 3511 | if (phydev->link) { |
| 3512 | u32 tempval1 = gfar_read(®s->maccfg1); |
| 3513 | u32 tempval = gfar_read(®s->maccfg2); |
| 3514 | u32 ecntrl = gfar_read(®s->ecntrl); |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 3515 | u32 tx_flow_oldval = (tempval & MACCFG1_TX_FLOW); |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3516 | |
| 3517 | if (phydev->duplex != priv->oldduplex) { |
| 3518 | if (!(phydev->duplex)) |
| 3519 | tempval &= ~(MACCFG2_FULL_DUPLEX); |
| 3520 | else |
| 3521 | tempval |= MACCFG2_FULL_DUPLEX; |
| 3522 | |
| 3523 | priv->oldduplex = phydev->duplex; |
| 3524 | } |
| 3525 | |
| 3526 | if (phydev->speed != priv->oldspeed) { |
| 3527 | switch (phydev->speed) { |
| 3528 | case 1000: |
| 3529 | tempval = |
| 3530 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII); |
| 3531 | |
| 3532 | ecntrl &= ~(ECNTRL_R100); |
| 3533 | break; |
| 3534 | case 100: |
| 3535 | case 10: |
| 3536 | tempval = |
| 3537 | ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); |
| 3538 | |
| 3539 | /* Reduced mode distinguishes |
| 3540 | * between 10 and 100 |
| 3541 | */ |
| 3542 | if (phydev->speed == SPEED_100) |
| 3543 | ecntrl |= ECNTRL_R100; |
| 3544 | else |
| 3545 | ecntrl &= ~(ECNTRL_R100); |
| 3546 | break; |
| 3547 | default: |
| 3548 | netif_warn(priv, link, priv->ndev, |
| 3549 | "Ack! Speed (%d) is not 10/100/1000!\n", |
| 3550 | phydev->speed); |
| 3551 | break; |
| 3552 | } |
| 3553 | |
| 3554 | priv->oldspeed = phydev->speed; |
| 3555 | } |
| 3556 | |
| 3557 | tempval1 &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW); |
| 3558 | tempval1 |= gfar_get_flowctrl_cfg(priv); |
| 3559 | |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 3560 | /* Turn last free buffer recording on */ |
| 3561 | if ((tempval1 & MACCFG1_TX_FLOW) && !tx_flow_oldval) { |
| 3562 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 3563 | rx_queue = priv->rx_queue[i]; |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 3564 | bdp = gfar_rxbd_lastfree(rx_queue); |
| 3565 | gfar_write(rx_queue->rfbptr, (u32)bdp); |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | priv->tx_actual_en = 1; |
| 3569 | } |
| 3570 | |
| 3571 | if (unlikely(!(tempval1 & MACCFG1_TX_FLOW) && tx_flow_oldval)) |
| 3572 | priv->tx_actual_en = 0; |
| 3573 | |
Claudiu Manoil | 6ce29b0 | 2014-04-30 14:27:21 +0300 | [diff] [blame] | 3574 | gfar_write(®s->maccfg1, tempval1); |
| 3575 | gfar_write(®s->maccfg2, tempval); |
| 3576 | gfar_write(®s->ecntrl, ecntrl); |
| 3577 | |
| 3578 | if (!priv->oldlink) |
| 3579 | priv->oldlink = 1; |
| 3580 | |
| 3581 | } else if (priv->oldlink) { |
| 3582 | priv->oldlink = 0; |
| 3583 | priv->oldspeed = 0; |
| 3584 | priv->oldduplex = -1; |
| 3585 | } |
| 3586 | |
| 3587 | if (netif_msg_link(priv)) |
| 3588 | phy_print_status(phydev); |
| 3589 | } |
| 3590 | |
Fabian Frederick | 94e5a2a | 2015-03-17 19:37:34 +0100 | [diff] [blame] | 3591 | static const struct of_device_id gfar_match[] = |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 3592 | { |
| 3593 | { |
| 3594 | .type = "network", |
| 3595 | .compatible = "gianfar", |
| 3596 | }, |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 3597 | { |
| 3598 | .compatible = "fsl,etsec2", |
| 3599 | }, |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 3600 | {}, |
| 3601 | }; |
Anton Vorontsov | e72701a | 2009-10-14 14:54:52 -0700 | [diff] [blame] | 3602 | MODULE_DEVICE_TABLE(of, gfar_match); |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 3603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | /* Structure for a device driver */ |
Grant Likely | 7488876 | 2011-02-22 21:05:51 -0700 | [diff] [blame] | 3605 | static struct platform_driver gfar_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 3606 | .driver = { |
| 3607 | .name = "fsl-gianfar", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 3608 | .pm = GFAR_PM_OPS, |
| 3609 | .of_match_table = gfar_match, |
| 3610 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | .probe = gfar_probe, |
| 3612 | .remove = gfar_remove, |
| 3613 | }; |
| 3614 | |
Axel Lin | db62f68 | 2011-11-27 16:44:17 +0000 | [diff] [blame] | 3615 | module_platform_driver(gfar_driver); |