blob: 5d6883dd01efd1cd0367d9698ff91b30de71da2c [file] [log] [blame]
Jan Ceuleers0977f812012-06-05 03:42:12 +00001/* drivers/net/ethernet/freescale/gianfar.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Gianfar Ethernet Driver
Andy Fleming7f7f5312005-11-11 12:38:59 -06004 * This driver is designed for the non-CPM ethernet controllers
5 * on the 85xx and 83xx family of integrated processors
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Based on 8260_io/fcc_enet.c
7 *
8 * Author: Andy Fleming
Kumar Gala4c8d3d92005-11-13 16:06:30 -08009 * Maintainer: Kumar Gala
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000010 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
Claudiu Manoil20862782014-02-17 12:53:14 +020012 * Copyright 2002-2009, 2011-2013 Freescale Semiconductor, Inc.
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000013 * Copyright 2007 MontaVista Software, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
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 Gala0bbaf062005-06-20 10:54:21 -050027 *
Andy Flemingb31a1d82008-12-16 15:29:15 -080028 * The driver is initialized through of_device. Configuration information
29 * is therefore conveyed through an OF-style device tree.
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
31 * The Gianfar Ethernet Controller uses a ring of buffer
32 * descriptors. The beginning is indicated by a register
Kumar Gala0bbaf062005-06-20 10:54:21 -050033 * 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 Torvalds1da177e2005-04-16 15:20:36 -070035 * last descriptor of the ring.
36 *
37 * When a packet is received, the RXF bit in the
Kumar Gala0bbaf062005-06-20 10:54:21 -050038 * IEVENT register is set, triggering an interrupt when the
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * 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 Flemingbb40dcb2005-09-23 22:54:21 -040042 * of frames or amount of time have passed). In NAPI, the
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * interrupt handler will signal there is work to be done, and
Francois Romieu0aa15382008-07-11 00:33:52 +020044 * exit. This method will start at the last known empty
Kumar Gala0bbaf062005-06-20 10:54:21 -050045 * descriptor, and process every subsequent descriptor until there
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * 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 Perches59deab22011-06-14 08:57:47 +000064#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
65#define DEBUG
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include <linux/string.h>
69#include <linux/errno.h>
Andy Flemingbb40dcb2005-09-23 22:54:21 -040070#include <linux/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <linux/slab.h>
72#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <linux/delay.h>
74#include <linux/netdevice.h>
75#include <linux/etherdevice.h>
76#include <linux/skbuff.h>
Kumar Gala0bbaf062005-06-20 10:54:21 -050077#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <linux/spinlock.h>
79#include <linux/mm.h>
Rob Herring5af50732013-09-17 14:28:33 -050080#include <linux/of_address.h>
81#include <linux/of_irq.h>
Grant Likelyfe192a42009-04-25 12:53:12 +000082#include <linux/of_mdio.h>
Andy Flemingb31a1d82008-12-16 15:29:15 -080083#include <linux/of_platform.h>
Kumar Gala0bbaf062005-06-20 10:54:21 -050084#include <linux/ip.h>
85#include <linux/tcp.h>
86#include <linux/udp.h>
Kumar Gala9c07b8842006-01-11 11:26:25 -080087#include <linux/in.h>
Manfred Rudigiercc772ab2010-04-08 23:10:03 +000088#include <linux/net_tstamp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#include <asm/io.h>
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +030091#ifdef CONFIG_PPC
Anton Vorontsov7d350972010-06-30 06:39:12 +000092#include <asm/reg.h>
Claudiu Manoil2969b1f2013-10-09 20:20:41 +030093#include <asm/mpc85xx.h>
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +030094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#include <asm/irq.h>
96#include <asm/uaccess.h>
97#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#include <linux/dma-mapping.h>
99#include <linux/crc32.h>
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400100#include <linux/mii.h>
101#include <linux/phy.h>
Andy Flemingb31a1d82008-12-16 15:29:15 -0800102#include <linux/phy_fixed.h>
103#include <linux/of.h>
David Daney4b6ba8a2010-10-26 15:07:13 -0700104#include <linux/of_net.h>
Claudiu Manoilfd31a952014-10-07 10:44:31 +0300105#include <linux/of_address.h>
106#include <linux/of_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108#include "gianfar.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110#define TX_TIMEOUT (1*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Andy Fleming7f7f5312005-11-11 12:38:59 -0600112const char gfar_driver_version[] = "1.3";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static int gfar_enet_open(struct net_device *dev);
115static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
Sebastian Siewiorab939902008-08-19 21:12:45 +0200116static void gfar_reset_task(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static void gfar_timeout(struct net_device *dev);
118static int gfar_close(struct net_device *dev);
Kevin Hao91c53f762014-12-24 14:05:44 +0800119static struct sk_buff *gfar_new_skb(struct net_device *dev,
120 dma_addr_t *bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121static int gfar_set_mac_address(struct net_device *dev);
122static int gfar_change_mtu(struct net_device *dev, int new_mtu);
David Howells7d12e782006-10-05 14:55:46 +0100123static irqreturn_t gfar_error(int irq, void *dev_id);
124static irqreturn_t gfar_transmit(int irq, void *dev_id);
125static irqreturn_t gfar_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void adjust_link(struct net_device *dev);
Claudiu Manoil6ce29b02014-04-30 14:27:21 +0300127static noinline void gfar_update_link_state(struct gfar_private *priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128static int init_phy(struct net_device *dev);
Grant Likely74888762011-02-22 21:05:51 -0700129static int gfar_probe(struct platform_device *ofdev);
Grant Likely2dc11582010-08-06 09:25:50 -0600130static int gfar_remove(struct platform_device *ofdev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400131static void free_skb_resources(struct gfar_private *priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static void gfar_set_multi(struct net_device *dev);
133static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
Kapil Junejad3c12872007-05-11 18:25:11 -0500134static void gfar_configure_serdes(struct net_device *dev);
Claudiu Manoilaeb12c52014-03-07 14:42:45 +0200135static int gfar_poll_rx(struct napi_struct *napi, int budget);
136static int gfar_poll_tx(struct napi_struct *napi, int budget);
137static int gfar_poll_rx_sq(struct napi_struct *napi, int budget);
138static int gfar_poll_tx_sq(struct napi_struct *napi, int budget);
Vitaly Woolf2d71c22006-11-07 13:27:02 +0300139#ifdef CONFIG_NET_POLL_CONTROLLER
140static void gfar_netpoll(struct net_device *dev);
141#endif
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000142int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
Claudiu Manoilc233cf402013-03-19 07:40:02 +0000143static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue);
Claudiu Manoil61db26c2013-02-14 05:00:05 +0000144static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
145 int amount_pull, struct napi_struct *napi);
Claudiu Manoilc10650b2014-02-17 12:53:18 +0200146static void gfar_halt_nodisable(struct gfar_private *priv);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600147static void gfar_clear_exact_match(struct net_device *dev);
Joe Perchesb6bc7652010-12-21 02:16:08 -0800148static void gfar_set_mac_for_addr(struct net_device *dev, int num,
149 const u8 *addr);
Andy Fleming26ccfc32009-03-10 12:58:28 +0000150static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152MODULE_AUTHOR("Freescale Semiconductor, Inc");
153MODULE_DESCRIPTION("Gianfar Ethernet Driver");
154MODULE_LICENSE("GPL");
155
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000156static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000157 dma_addr_t buf)
158{
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000159 u32 lstatus;
160
Claudiu Manoila7312d52015-03-13 10:36:28 +0200161 bdp->bufPtr = cpu_to_be32(buf);
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000162
163 lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000164 if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1)
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000165 lstatus |= BD_LFLAG(RXBD_WRAP);
166
Claudiu Manoild55398b2014-10-07 10:44:35 +0300167 gfar_wmb();
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000168
Claudiu Manoila7312d52015-03-13 10:36:28 +0200169 bdp->lstatus = cpu_to_be32(lstatus);
Anton Vorontsov8a102fe2009-10-12 06:00:37 +0000170}
171
Anton Vorontsov87283272009-10-12 06:00:39 +0000172static int gfar_init_bds(struct net_device *ndev)
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000173{
Anton Vorontsov87283272009-10-12 06:00:39 +0000174 struct gfar_private *priv = netdev_priv(ndev);
Matei Pavaluca45b679c92014-10-27 10:42:44 +0200175 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000176 struct gfar_priv_tx_q *tx_queue = NULL;
177 struct gfar_priv_rx_q *rx_queue = NULL;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000178 struct txbd8 *txbdp;
179 struct rxbd8 *rxbdp;
Kevin Hao03366a332014-12-24 14:05:45 +0800180 u32 __iomem *rfbptr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000181 int i, j;
Kevin Hao0a4b5a22014-12-11 14:08:41 +0800182 dma_addr_t bufaddr;
Anton Vorontsov87283272009-10-12 06:00:39 +0000183
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000184 for (i = 0; i < priv->num_tx_queues; i++) {
185 tx_queue = priv->tx_queue[i];
186 /* Initialize some variables in our dev structure */
187 tx_queue->num_txbdfree = tx_queue->tx_ring_size;
188 tx_queue->dirty_tx = tx_queue->tx_bd_base;
189 tx_queue->cur_tx = tx_queue->tx_bd_base;
190 tx_queue->skb_curtx = 0;
191 tx_queue->skb_dirtytx = 0;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000192
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000193 /* Initialize Transmit Descriptor Ring */
194 txbdp = tx_queue->tx_bd_base;
195 for (j = 0; j < tx_queue->tx_ring_size; j++) {
196 txbdp->lstatus = 0;
197 txbdp->bufPtr = 0;
198 txbdp++;
Anton Vorontsov87283272009-10-12 06:00:39 +0000199 }
200
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000201 /* Set the last descriptor in the ring to indicate wrap */
202 txbdp--;
Claudiu Manoila7312d52015-03-13 10:36:28 +0200203 txbdp->status = cpu_to_be16(be16_to_cpu(txbdp->status) |
204 TXBD_WRAP);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000205 }
206
Matei Pavaluca45b679c92014-10-27 10:42:44 +0200207 rfbptr = &regs->rfbptr0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000208 for (i = 0; i < priv->num_rx_queues; i++) {
209 rx_queue = priv->rx_queue[i];
210 rx_queue->cur_rx = rx_queue->rx_bd_base;
211 rx_queue->skb_currx = 0;
212 rxbdp = rx_queue->rx_bd_base;
213
214 for (j = 0; j < rx_queue->rx_ring_size; j++) {
215 struct sk_buff *skb = rx_queue->rx_skbuff[j];
216
217 if (skb) {
Claudiu Manoila7312d52015-03-13 10:36:28 +0200218 bufaddr = be32_to_cpu(rxbdp->bufPtr);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000219 } else {
Kevin Hao0a4b5a22014-12-11 14:08:41 +0800220 skb = gfar_new_skb(ndev, &bufaddr);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000221 if (!skb) {
Joe Perches59deab22011-06-14 08:57:47 +0000222 netdev_err(ndev, "Can't allocate RX buffers\n");
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +0000223 return -ENOMEM;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000224 }
225 rx_queue->rx_skbuff[j] = skb;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000226 }
227
Kevin Hao0a4b5a22014-12-11 14:08:41 +0800228 gfar_init_rxbdp(rx_queue, rxbdp, bufaddr);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000229 rxbdp++;
230 }
231
Matei Pavaluca45b679c92014-10-27 10:42:44 +0200232 rx_queue->rfbptr = rfbptr;
233 rfbptr += 2;
Anton Vorontsov87283272009-10-12 06:00:39 +0000234 }
235
236 return 0;
237}
238
239static int gfar_alloc_skb_resources(struct net_device *ndev)
240{
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000241 void *vaddr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000242 dma_addr_t addr;
243 int i, j, k;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000244 struct gfar_private *priv = netdev_priv(ndev);
Claudiu Manoil369ec162013-02-14 05:00:02 +0000245 struct device *dev = priv->dev;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000246 struct gfar_priv_tx_q *tx_queue = NULL;
247 struct gfar_priv_rx_q *rx_queue = NULL;
248
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000249 priv->total_tx_ring_size = 0;
250 for (i = 0; i < priv->num_tx_queues; i++)
251 priv->total_tx_ring_size += priv->tx_queue[i]->tx_ring_size;
252
253 priv->total_rx_ring_size = 0;
254 for (i = 0; i < priv->num_rx_queues; i++)
255 priv->total_rx_ring_size += priv->rx_queue[i]->rx_ring_size;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000256
257 /* Allocate memory for the buffer descriptors */
Anton Vorontsov87283272009-10-12 06:00:39 +0000258 vaddr = dma_alloc_coherent(dev,
Joe Perchesd0320f72013-03-14 13:07:21 +0000259 (priv->total_tx_ring_size *
260 sizeof(struct txbd8)) +
261 (priv->total_rx_ring_size *
262 sizeof(struct rxbd8)),
263 &addr, GFP_KERNEL);
264 if (!vaddr)
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000265 return -ENOMEM;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000266
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000267 for (i = 0; i < priv->num_tx_queues; i++) {
268 tx_queue = priv->tx_queue[i];
Joe Perches43d620c2011-06-16 19:08:06 +0000269 tx_queue->tx_bd_base = vaddr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000270 tx_queue->tx_bd_dma_base = addr;
271 tx_queue->dev = ndev;
272 /* enet DMA only understands physical addresses */
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000273 addr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
274 vaddr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000275 }
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000276
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000277 /* Start the rx descriptor ring where the tx ring leaves off */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000278 for (i = 0; i < priv->num_rx_queues; i++) {
279 rx_queue = priv->rx_queue[i];
Joe Perches43d620c2011-06-16 19:08:06 +0000280 rx_queue->rx_bd_base = vaddr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000281 rx_queue->rx_bd_dma_base = addr;
282 rx_queue->dev = ndev;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000283 addr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
284 vaddr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000285 }
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000286
287 /* Setup the skbuff rings */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000288 for (i = 0; i < priv->num_tx_queues; i++) {
289 tx_queue = priv->tx_queue[i];
Joe Perches14f8dc42013-02-07 11:46:27 +0000290 tx_queue->tx_skbuff =
291 kmalloc_array(tx_queue->tx_ring_size,
292 sizeof(*tx_queue->tx_skbuff),
293 GFP_KERNEL);
294 if (!tx_queue->tx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000295 goto cleanup;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000296
297 for (k = 0; k < tx_queue->tx_ring_size; k++)
298 tx_queue->tx_skbuff[k] = NULL;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000299 }
300
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000301 for (i = 0; i < priv->num_rx_queues; i++) {
302 rx_queue = priv->rx_queue[i];
Joe Perches14f8dc42013-02-07 11:46:27 +0000303 rx_queue->rx_skbuff =
304 kmalloc_array(rx_queue->rx_ring_size,
305 sizeof(*rx_queue->rx_skbuff),
306 GFP_KERNEL);
307 if (!rx_queue->rx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000308 goto cleanup;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000309
310 for (j = 0; j < rx_queue->rx_ring_size; j++)
311 rx_queue->rx_skbuff[j] = NULL;
312 }
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000313
Anton Vorontsov87283272009-10-12 06:00:39 +0000314 if (gfar_init_bds(ndev))
315 goto cleanup;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000316
317 return 0;
318
319cleanup:
320 free_skb_resources(priv);
321 return -ENOMEM;
322}
323
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000324static void gfar_init_tx_rx_base(struct gfar_private *priv)
325{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000326 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Anton Vorontsov18294ad2009-11-04 12:53:00 +0000327 u32 __iomem *baddr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000328 int i;
329
330 baddr = &regs->tbase0;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000331 for (i = 0; i < priv->num_tx_queues; i++) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000332 gfar_write(baddr, priv->tx_queue[i]->tx_bd_dma_base);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000333 baddr += 2;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000334 }
335
336 baddr = &regs->rbase0;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000337 for (i = 0; i < priv->num_rx_queues; i++) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000338 gfar_write(baddr, priv->rx_queue[i]->rx_bd_dma_base);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000339 baddr += 2;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000340 }
341}
342
Matei Pavaluca45b679c92014-10-27 10:42:44 +0200343static void gfar_init_rqprm(struct gfar_private *priv)
344{
345 struct gfar __iomem *regs = priv->gfargrp[0].regs;
346 u32 __iomem *baddr;
347 int i;
348
349 baddr = &regs->rqprm0;
350 for (i = 0; i < priv->num_rx_queues; i++) {
351 gfar_write(baddr, priv->rx_queue[i]->rx_ring_size |
352 (DEFAULT_RX_LFC_THR << FBTHR_SHIFT));
353 baddr++;
354 }
355}
356
Claudiu Manoil88302642014-02-24 12:13:43 +0200357static void gfar_rx_buff_size_config(struct gfar_private *priv)
358{
Claudiu Manoilf5b720b2014-10-15 19:11:46 +0300359 int frame_size = priv->ndev->mtu + ETH_HLEN + ETH_FCS_LEN;
Claudiu Manoil88302642014-02-24 12:13:43 +0200360
361 /* set this when rx hw offload (TOE) functions are being used */
362 priv->uses_rxfcb = 0;
363
364 if (priv->ndev->features & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX))
365 priv->uses_rxfcb = 1;
366
367 if (priv->hwts_rx_en)
368 priv->uses_rxfcb = 1;
369
370 if (priv->uses_rxfcb)
371 frame_size += GMAC_FCB_LEN;
372
373 frame_size += priv->padding;
374
375 frame_size = (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
376 INCREMENTAL_BUFFER_SIZE;
377
378 priv->rx_buffer_size = frame_size;
379}
380
Claudiu Manoila328ac92014-02-24 12:13:42 +0200381static void gfar_mac_rx_config(struct gfar_private *priv)
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000382{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000383 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000384 u32 rctrl = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000385
Sandeep Gopalpet1ccb8382009-12-16 01:14:58 +0000386 if (priv->rx_filer_enable) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000387 rctrl |= RCTRL_FILREN;
Sandeep Gopalpet1ccb8382009-12-16 01:14:58 +0000388 /* Program the RIR0 reg with the required distribution */
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200389 if (priv->poll_mode == GFAR_SQ_POLLING)
390 gfar_write(&regs->rir0, DEFAULT_2RXQ_RIR0);
391 else /* GFAR_MQ_POLLING */
392 gfar_write(&regs->rir0, DEFAULT_8RXQ_RIR0);
Sandeep Gopalpet1ccb8382009-12-16 01:14:58 +0000393 }
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000394
Claudiu Manoilf5ae6272013-01-23 00:18:36 +0000395 /* Restore PROMISC mode */
Claudiu Manoila328ac92014-02-24 12:13:42 +0200396 if (priv->ndev->flags & IFF_PROMISC)
Claudiu Manoilf5ae6272013-01-23 00:18:36 +0000397 rctrl |= RCTRL_PROM;
398
Claudiu Manoil88302642014-02-24 12:13:43 +0200399 if (priv->ndev->features & NETIF_F_RXCSUM)
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000400 rctrl |= RCTRL_CHECKSUMMING;
401
Claudiu Manoil88302642014-02-24 12:13:43 +0200402 if (priv->extended_hash)
403 rctrl |= RCTRL_EXTHASH | RCTRL_EMEN;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000404
405 if (priv->padding) {
406 rctrl &= ~RCTRL_PAL_MASK;
407 rctrl |= RCTRL_PADDING(priv->padding);
408 }
409
Manfred Rudigier97553f72010-06-11 01:49:05 +0000410 /* Enable HW time stamping if requested from user space */
Claudiu Manoil88302642014-02-24 12:13:43 +0200411 if (priv->hwts_rx_en)
Manfred Rudigier97553f72010-06-11 01:49:05 +0000412 rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE;
413
Claudiu Manoil88302642014-02-24 12:13:43 +0200414 if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_RX)
Sebastian Pöhnb852b722011-07-26 00:03:13 +0000415 rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000416
Matei Pavaluca45b679c92014-10-27 10:42:44 +0200417 /* Clear the LFC bit */
418 gfar_write(&regs->rctrl, rctrl);
419 /* Init flow control threshold values */
420 gfar_init_rqprm(priv);
421 gfar_write(&regs->ptv, DEFAULT_LFC_PTVVAL);
422 rctrl |= RCTRL_LFC;
423
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000424 /* Init rctrl based on our settings */
425 gfar_write(&regs->rctrl, rctrl);
Claudiu Manoila328ac92014-02-24 12:13:42 +0200426}
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000427
Claudiu Manoila328ac92014-02-24 12:13:42 +0200428static void gfar_mac_tx_config(struct gfar_private *priv)
429{
430 struct gfar __iomem *regs = priv->gfargrp[0].regs;
431 u32 tctrl = 0;
432
433 if (priv->ndev->features & NETIF_F_IP_CSUM)
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000434 tctrl |= TCTRL_INIT_CSUM;
435
Claudiu Manoilb98b8ba2012-09-23 22:39:08 +0000436 if (priv->prio_sched_en)
437 tctrl |= TCTRL_TXSCHED_PRIO;
438 else {
439 tctrl |= TCTRL_TXSCHED_WRRS;
440 gfar_write(&regs->tr03wt, DEFAULT_WRRS_WEIGHT);
441 gfar_write(&regs->tr47wt, DEFAULT_WRRS_WEIGHT);
442 }
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000443
Claudiu Manoil88302642014-02-24 12:13:43 +0200444 if (priv->ndev->features & NETIF_F_HW_VLAN_CTAG_TX)
445 tctrl |= TCTRL_VLINS;
446
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000447 gfar_write(&regs->tctrl, tctrl);
Anton Vorontsov826aa4a2009-10-12 06:00:34 +0000448}
449
Claudiu Manoilf19015b2014-02-24 12:13:46 +0200450static void gfar_configure_coalescing(struct gfar_private *priv,
451 unsigned long tx_mask, unsigned long rx_mask)
452{
453 struct gfar __iomem *regs = priv->gfargrp[0].regs;
454 u32 __iomem *baddr;
455
456 if (priv->mode == MQ_MG_MODE) {
457 int i = 0;
458
459 baddr = &regs->txic0;
460 for_each_set_bit(i, &tx_mask, priv->num_tx_queues) {
461 gfar_write(baddr + i, 0);
462 if (likely(priv->tx_queue[i]->txcoalescing))
463 gfar_write(baddr + i, priv->tx_queue[i]->txic);
464 }
465
466 baddr = &regs->rxic0;
467 for_each_set_bit(i, &rx_mask, priv->num_rx_queues) {
468 gfar_write(baddr + i, 0);
469 if (likely(priv->rx_queue[i]->rxcoalescing))
470 gfar_write(baddr + i, priv->rx_queue[i]->rxic);
471 }
472 } else {
473 /* Backward compatible case -- even if we enable
474 * multiple queues, there's only single reg to program
475 */
476 gfar_write(&regs->txic, 0);
477 if (likely(priv->tx_queue[0]->txcoalescing))
478 gfar_write(&regs->txic, priv->tx_queue[0]->txic);
479
480 gfar_write(&regs->rxic, 0);
481 if (unlikely(priv->rx_queue[0]->rxcoalescing))
482 gfar_write(&regs->rxic, priv->rx_queue[0]->rxic);
483 }
484}
485
486void gfar_configure_coalescing_all(struct gfar_private *priv)
487{
488 gfar_configure_coalescing(priv, 0xFF, 0xFF);
489}
490
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000491static struct net_device_stats *gfar_get_stats(struct net_device *dev)
492{
493 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000494 unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0;
495 unsigned long tx_packets = 0, tx_bytes = 0;
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000496 int i;
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000497
498 for (i = 0; i < priv->num_rx_queues; i++) {
499 rx_packets += priv->rx_queue[i]->stats.rx_packets;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000500 rx_bytes += priv->rx_queue[i]->stats.rx_bytes;
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000501 rx_dropped += priv->rx_queue[i]->stats.rx_dropped;
502 }
503
504 dev->stats.rx_packets = rx_packets;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000505 dev->stats.rx_bytes = rx_bytes;
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000506 dev->stats.rx_dropped = rx_dropped;
507
508 for (i = 0; i < priv->num_tx_queues; i++) {
Eric Dumazet1ac9ad12011-01-12 12:13:14 +0000509 tx_bytes += priv->tx_queue[i]->stats.tx_bytes;
510 tx_packets += priv->tx_queue[i]->stats.tx_packets;
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000511 }
512
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000513 dev->stats.tx_bytes = tx_bytes;
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000514 dev->stats.tx_packets = tx_packets;
515
516 return &dev->stats;
517}
518
Andy Fleming26ccfc32009-03-10 12:58:28 +0000519static const struct net_device_ops gfar_netdev_ops = {
520 .ndo_open = gfar_enet_open,
521 .ndo_start_xmit = gfar_start_xmit,
522 .ndo_stop = gfar_close,
523 .ndo_change_mtu = gfar_change_mtu,
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000524 .ndo_set_features = gfar_set_features,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000525 .ndo_set_rx_mode = gfar_set_multi,
Andy Fleming26ccfc32009-03-10 12:58:28 +0000526 .ndo_tx_timeout = gfar_timeout,
527 .ndo_do_ioctl = gfar_ioctl,
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000528 .ndo_get_stats = gfar_get_stats,
Ben Hutchings240c1022009-07-09 17:54:35 +0000529 .ndo_set_mac_address = eth_mac_addr,
530 .ndo_validate_addr = eth_validate_addr,
Andy Fleming26ccfc32009-03-10 12:58:28 +0000531#ifdef CONFIG_NET_POLL_CONTROLLER
532 .ndo_poll_controller = gfar_netpoll,
533#endif
534};
535
Claudiu Manoilefeddce2014-02-17 12:53:17 +0200536static void gfar_ints_disable(struct gfar_private *priv)
537{
538 int i;
539 for (i = 0; i < priv->num_grps; i++) {
540 struct gfar __iomem *regs = priv->gfargrp[i].regs;
541 /* Clear IEVENT */
542 gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
543
544 /* Initialize IMASK */
545 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
546 }
547}
548
549static void gfar_ints_enable(struct gfar_private *priv)
550{
551 int i;
552 for (i = 0; i < priv->num_grps; i++) {
553 struct gfar __iomem *regs = priv->gfargrp[i].regs;
554 /* Unmask the interrupts we look for */
555 gfar_write(&regs->imask, IMASK_DEFAULT);
556 }
557}
558
Kevin Hao91c53f762014-12-24 14:05:44 +0800559static void lock_tx_qs(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000560{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000561 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000562
563 for (i = 0; i < priv->num_tx_queues; i++)
564 spin_lock(&priv->tx_queue[i]->txlock);
565}
566
Kevin Hao91c53f762014-12-24 14:05:44 +0800567static void unlock_tx_qs(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000568{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000569 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000570
571 for (i = 0; i < priv->num_tx_queues; i++)
572 spin_unlock(&priv->tx_queue[i]->txlock);
573}
574
Claudiu Manoil20862782014-02-17 12:53:14 +0200575static int gfar_alloc_tx_queues(struct gfar_private *priv)
576{
577 int i;
578
579 for (i = 0; i < priv->num_tx_queues; i++) {
580 priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q),
581 GFP_KERNEL);
582 if (!priv->tx_queue[i])
583 return -ENOMEM;
584
585 priv->tx_queue[i]->tx_skbuff = NULL;
586 priv->tx_queue[i]->qindex = i;
587 priv->tx_queue[i]->dev = priv->ndev;
588 spin_lock_init(&(priv->tx_queue[i]->txlock));
589 }
590 return 0;
591}
592
593static int gfar_alloc_rx_queues(struct gfar_private *priv)
594{
595 int i;
596
597 for (i = 0; i < priv->num_rx_queues; i++) {
598 priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q),
599 GFP_KERNEL);
600 if (!priv->rx_queue[i])
601 return -ENOMEM;
602
603 priv->rx_queue[i]->rx_skbuff = NULL;
604 priv->rx_queue[i]->qindex = i;
605 priv->rx_queue[i]->dev = priv->ndev;
Claudiu Manoil20862782014-02-17 12:53:14 +0200606 }
607 return 0;
608}
609
610static void gfar_free_tx_queues(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000611{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000612 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000613
614 for (i = 0; i < priv->num_tx_queues; i++)
615 kfree(priv->tx_queue[i]);
616}
617
Claudiu Manoil20862782014-02-17 12:53:14 +0200618static void gfar_free_rx_queues(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000619{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000620 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000621
622 for (i = 0; i < priv->num_rx_queues; i++)
623 kfree(priv->rx_queue[i]);
624}
625
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000626static void unmap_group_regs(struct gfar_private *priv)
627{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000628 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000629
630 for (i = 0; i < MAXGROUPS; i++)
631 if (priv->gfargrp[i].regs)
632 iounmap(priv->gfargrp[i].regs);
633}
634
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000635static void free_gfar_dev(struct gfar_private *priv)
636{
637 int i, j;
638
639 for (i = 0; i < priv->num_grps; i++)
640 for (j = 0; j < GFAR_NUM_IRQS; j++) {
641 kfree(priv->gfargrp[i].irqinfo[j]);
642 priv->gfargrp[i].irqinfo[j] = NULL;
643 }
644
645 free_netdev(priv->ndev);
646}
647
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000648static void disable_napi(struct gfar_private *priv)
649{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000650 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000651
Claudiu Manoilaeb12c52014-03-07 14:42:45 +0200652 for (i = 0; i < priv->num_grps; i++) {
653 napi_disable(&priv->gfargrp[i].napi_rx);
654 napi_disable(&priv->gfargrp[i].napi_tx);
655 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000656}
657
658static void enable_napi(struct gfar_private *priv)
659{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000660 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000661
Claudiu Manoilaeb12c52014-03-07 14:42:45 +0200662 for (i = 0; i < priv->num_grps; i++) {
663 napi_enable(&priv->gfargrp[i].napi_rx);
664 napi_enable(&priv->gfargrp[i].napi_tx);
665 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000666}
667
668static int gfar_parse_group(struct device_node *np,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000669 struct gfar_private *priv, const char *model)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000670{
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000671 struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps];
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000672 int i;
673
Paul Gortmaker7c1e7e92013-02-04 09:49:42 +0000674 for (i = 0; i < GFAR_NUM_IRQS; i++) {
675 grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo),
676 GFP_KERNEL);
677 if (!grp->irqinfo[i])
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000678 return -ENOMEM;
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000679 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000680
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000681 grp->regs = of_iomap(np, 0);
682 if (!grp->regs)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000683 return -ENOMEM;
684
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000685 gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000686
687 /* If we aren't the FEC we have multiple interrupts */
688 if (model && strcasecmp(model, "FEC")) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000689 gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1);
690 gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2);
691 if (gfar_irq(grp, TX)->irq == NO_IRQ ||
692 gfar_irq(grp, RX)->irq == NO_IRQ ||
693 gfar_irq(grp, ER)->irq == NO_IRQ)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000694 return -EINVAL;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000695 }
696
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000697 grp->priv = priv;
698 spin_lock_init(&grp->grplock);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000699 if (priv->mode == MQ_MG_MODE) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200700 u32 *rxq_mask, *txq_mask;
701 rxq_mask = (u32 *)of_get_property(np, "fsl,rx-bit-map", NULL);
702 txq_mask = (u32 *)of_get_property(np, "fsl,tx-bit-map", NULL);
703
704 if (priv->poll_mode == GFAR_SQ_POLLING) {
705 /* One Q per interrupt group: Q0 to G0, Q1 to G1 */
706 grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
707 grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
708 } else { /* GFAR_MQ_POLLING */
709 grp->rx_bit_map = rxq_mask ?
710 *rxq_mask : (DEFAULT_MAPPING >> priv->num_grps);
711 grp->tx_bit_map = txq_mask ?
712 *txq_mask : (DEFAULT_MAPPING >> priv->num_grps);
713 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000714 } else {
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000715 grp->rx_bit_map = 0xFF;
716 grp->tx_bit_map = 0xFF;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000717 }
Claudiu Manoil20862782014-02-17 12:53:14 +0200718
719 /* bit_map's MSB is q0 (from q0 to q7) but, for_each_set_bit parses
720 * right to left, so we need to revert the 8 bits to get the q index
721 */
722 grp->rx_bit_map = bitrev8(grp->rx_bit_map);
723 grp->tx_bit_map = bitrev8(grp->tx_bit_map);
724
725 /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values,
726 * also assign queues to groups
727 */
728 for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200729 if (!grp->rx_queue)
730 grp->rx_queue = priv->rx_queue[i];
Claudiu Manoil20862782014-02-17 12:53:14 +0200731 grp->num_rx_queues++;
732 grp->rstat |= (RSTAT_CLEAR_RHALT >> i);
733 priv->rqueue |= ((RQUEUE_EN0 | RQUEUE_EX0) >> i);
734 priv->rx_queue[i]->grp = grp;
735 }
736
737 for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200738 if (!grp->tx_queue)
739 grp->tx_queue = priv->tx_queue[i];
Claudiu Manoil20862782014-02-17 12:53:14 +0200740 grp->num_tx_queues++;
741 grp->tstat |= (TSTAT_CLEAR_THALT >> i);
742 priv->tqueue |= (TQUEUE_EN0 >> i);
743 priv->tx_queue[i]->grp = grp;
744 }
745
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000746 priv->num_grps++;
747
748 return 0;
749}
750
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100751static int gfar_of_group_count(struct device_node *np)
752{
753 struct device_node *child;
754 int num = 0;
755
756 for_each_available_child_of_node(np, child)
757 if (!of_node_cmp(child->name, "queue-group"))
758 num++;
759
760 return num;
761}
762
Grant Likely2dc11582010-08-06 09:25:50 -0600763static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
Andy Flemingb31a1d82008-12-16 15:29:15 -0800764{
Andy Flemingb31a1d82008-12-16 15:29:15 -0800765 const char *model;
766 const char *ctype;
767 const void *mac_addr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000768 int err = 0, i;
769 struct net_device *dev = NULL;
770 struct gfar_private *priv = NULL;
Grant Likely61c7a082010-04-13 16:12:29 -0700771 struct device_node *np = ofdev->dev.of_node;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000772 struct device_node *child = NULL;
Andy Fleming4d7902f2009-02-04 16:43:44 -0800773 const u32 *stash;
774 const u32 *stash_len;
775 const u32 *stash_idx;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000776 unsigned int num_tx_qs, num_rx_qs;
777 u32 *tx_queues, *rx_queues;
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200778 unsigned short mode, poll_mode;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800779
Kevin Hao4b222ca2015-01-28 20:06:48 +0800780 if (!np)
Andy Flemingb31a1d82008-12-16 15:29:15 -0800781 return -ENODEV;
782
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200783 if (of_device_is_compatible(np, "fsl,etsec2")) {
784 mode = MQ_MG_MODE;
785 poll_mode = GFAR_SQ_POLLING;
786 } else {
787 mode = SQ_SG_MODE;
788 poll_mode = GFAR_SQ_POLLING;
789 }
790
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200791 /* parse the num of HW tx and rx queues */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000792 tx_queues = (u32 *)of_get_property(np, "fsl,num_tx_queues", NULL);
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200793 rx_queues = (u32 *)of_get_property(np, "fsl,num_rx_queues", NULL);
794
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200795 if (mode == SQ_SG_MODE) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200796 num_tx_qs = 1;
797 num_rx_qs = 1;
798 } else { /* MQ_MG_MODE */
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200799 /* get the actual number of supported groups */
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100800 unsigned int num_grps = gfar_of_group_count(np);
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200801
802 if (num_grps == 0 || num_grps > MAXGROUPS) {
803 dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n",
804 num_grps);
805 pr_err("Cannot do alloc_etherdev, aborting\n");
806 return -EINVAL;
807 }
808
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200809 if (poll_mode == GFAR_SQ_POLLING) {
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200810 num_tx_qs = num_grps; /* one txq per int group */
811 num_rx_qs = num_grps; /* one rxq per int group */
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200812 } else { /* GFAR_MQ_POLLING */
813 num_tx_qs = tx_queues ? *tx_queues : 1;
814 num_rx_qs = rx_queues ? *rx_queues : 1;
815 }
816 }
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000817
818 if (num_tx_qs > MAX_TX_QS) {
Joe Perches59deab22011-06-14 08:57:47 +0000819 pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n",
820 num_tx_qs, MAX_TX_QS);
821 pr_err("Cannot do alloc_etherdev, aborting\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000822 return -EINVAL;
823 }
824
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000825 if (num_rx_qs > MAX_RX_QS) {
Joe Perches59deab22011-06-14 08:57:47 +0000826 pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n",
827 num_rx_qs, MAX_RX_QS);
828 pr_err("Cannot do alloc_etherdev, aborting\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000829 return -EINVAL;
830 }
831
832 *pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs);
833 dev = *pdev;
834 if (NULL == dev)
835 return -ENOMEM;
836
837 priv = netdev_priv(dev);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000838 priv->ndev = dev;
839
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200840 priv->mode = mode;
841 priv->poll_mode = poll_mode;
842
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000843 priv->num_tx_queues = num_tx_qs;
Ben Hutchingsfe069122010-09-27 08:27:37 +0000844 netif_set_real_num_rx_queues(dev, num_rx_qs);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000845 priv->num_rx_queues = num_rx_qs;
Claudiu Manoil20862782014-02-17 12:53:14 +0200846
847 err = gfar_alloc_tx_queues(priv);
848 if (err)
849 goto tx_alloc_failed;
850
851 err = gfar_alloc_rx_queues(priv);
852 if (err)
853 goto rx_alloc_failed;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800854
Jan Ceuleers0977f812012-06-05 03:42:12 +0000855 /* Init Rx queue filer rule set linked list */
Sebastian Poehn4aa3a712011-06-20 13:57:59 -0700856 INIT_LIST_HEAD(&priv->rx_list.list);
857 priv->rx_list.count = 0;
858 mutex_init(&priv->rx_queue_access);
859
Andy Flemingb31a1d82008-12-16 15:29:15 -0800860 model = of_get_property(np, "model", NULL);
861
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000862 for (i = 0; i < MAXGROUPS; i++)
863 priv->gfargrp[i].regs = NULL;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800864
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000865 /* Parse and initialize group specific information */
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200866 if (priv->mode == MQ_MG_MODE) {
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100867 for_each_available_child_of_node(np, child) {
868 if (of_node_cmp(child->name, "queue-group"))
869 continue;
870
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000871 err = gfar_parse_group(child, priv, model);
872 if (err)
873 goto err_grp_init;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800874 }
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200875 } else { /* SQ_SG_MODE */
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000876 err = gfar_parse_group(np, priv, model);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000877 if (err)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000878 goto err_grp_init;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800879 }
880
Andy Fleming4d7902f2009-02-04 16:43:44 -0800881 stash = of_get_property(np, "bd-stash", NULL);
882
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000883 if (stash) {
Andy Fleming4d7902f2009-02-04 16:43:44 -0800884 priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
885 priv->bd_stash_en = 1;
886 }
887
888 stash_len = of_get_property(np, "rx-stash-len", NULL);
889
890 if (stash_len)
891 priv->rx_stash_size = *stash_len;
892
893 stash_idx = of_get_property(np, "rx-stash-idx", NULL);
894
895 if (stash_idx)
896 priv->rx_stash_index = *stash_idx;
897
898 if (stash_len || stash_idx)
899 priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
900
Andy Flemingb31a1d82008-12-16 15:29:15 -0800901 mac_addr = of_get_mac_address(np);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000902
Andy Flemingb31a1d82008-12-16 15:29:15 -0800903 if (mac_addr)
Joe Perches6a3c910c2011-11-16 09:38:02 +0000904 memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800905
906 if (model && !strcasecmp(model, "TSEC"))
Claudiu Manoil34018fd2014-02-17 12:53:15 +0200907 priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000908 FSL_GIANFAR_DEV_HAS_COALESCE |
909 FSL_GIANFAR_DEV_HAS_RMON |
910 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
911
Andy Flemingb31a1d82008-12-16 15:29:15 -0800912 if (model && !strcasecmp(model, "eTSEC"))
Claudiu Manoil34018fd2014-02-17 12:53:15 +0200913 priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000914 FSL_GIANFAR_DEV_HAS_COALESCE |
915 FSL_GIANFAR_DEV_HAS_RMON |
916 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000917 FSL_GIANFAR_DEV_HAS_CSUM |
918 FSL_GIANFAR_DEV_HAS_VLAN |
919 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
920 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
921 FSL_GIANFAR_DEV_HAS_TIMER;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800922
923 ctype = of_get_property(np, "phy-connection-type", NULL);
924
925 /* We only care about rgmii-id. The rest are autodetected */
926 if (ctype && !strcmp(ctype, "rgmii-id"))
927 priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
928 else
929 priv->interface = PHY_INTERFACE_MODE_MII;
930
931 if (of_get_property(np, "fsl,magic-packet", NULL))
932 priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
933
Grant Likelyfe192a42009-04-25 12:53:12 +0000934 priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800935
Florian Fainellibe403642014-05-22 09:47:48 -0700936 /* In the case of a fixed PHY, the DT node associated
937 * to the PHY is the Ethernet MAC DT node.
938 */
Uwe Kleine-König6f2c9bd2014-08-07 22:17:07 +0200939 if (!priv->phy_node && of_phy_is_fixed_link(np)) {
Florian Fainellibe403642014-05-22 09:47:48 -0700940 err = of_phy_register_fixed_link(np);
941 if (err)
942 goto err_grp_init;
943
Uwe Kleine-König6f2c9bd2014-08-07 22:17:07 +0200944 priv->phy_node = of_node_get(np);
Florian Fainellibe403642014-05-22 09:47:48 -0700945 }
946
Andy Flemingb31a1d82008-12-16 15:29:15 -0800947 /* Find the TBI PHY. If it's not there, we don't support SGMII */
Grant Likelyfe192a42009-04-25 12:53:12 +0000948 priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800949
950 return 0;
951
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000952err_grp_init:
953 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +0200954rx_alloc_failed:
955 gfar_free_rx_queues(priv);
956tx_alloc_failed:
957 gfar_free_tx_queues(priv);
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000958 free_gfar_dev(priv);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800959 return err;
960}
961
Ben Hutchingsca0c88c2013-11-18 23:05:27 +0000962static int gfar_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Manfred Rudigiercc772ab2010-04-08 23:10:03 +0000963{
964 struct hwtstamp_config config;
965 struct gfar_private *priv = netdev_priv(netdev);
966
967 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
968 return -EFAULT;
969
970 /* reserved for future extensions */
971 if (config.flags)
972 return -EINVAL;
973
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +0000974 switch (config.tx_type) {
975 case HWTSTAMP_TX_OFF:
976 priv->hwts_tx_en = 0;
977 break;
978 case HWTSTAMP_TX_ON:
979 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
980 return -ERANGE;
981 priv->hwts_tx_en = 1;
982 break;
983 default:
Manfred Rudigiercc772ab2010-04-08 23:10:03 +0000984 return -ERANGE;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +0000985 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +0000986
987 switch (config.rx_filter) {
988 case HWTSTAMP_FILTER_NONE:
Manfred Rudigier97553f72010-06-11 01:49:05 +0000989 if (priv->hwts_rx_en) {
Manfred Rudigier97553f72010-06-11 01:49:05 +0000990 priv->hwts_rx_en = 0;
Claudiu Manoil08511332014-02-24 12:13:45 +0200991 reset_gfar(netdev);
Manfred Rudigier97553f72010-06-11 01:49:05 +0000992 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +0000993 break;
994 default:
995 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
996 return -ERANGE;
Manfred Rudigier97553f72010-06-11 01:49:05 +0000997 if (!priv->hwts_rx_en) {
Manfred Rudigier97553f72010-06-11 01:49:05 +0000998 priv->hwts_rx_en = 1;
Claudiu Manoil08511332014-02-24 12:13:45 +0200999 reset_gfar(netdev);
Manfred Rudigier97553f72010-06-11 01:49:05 +00001000 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001001 config.rx_filter = HWTSTAMP_FILTER_ALL;
1002 break;
1003 }
1004
1005 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1006 -EFAULT : 0;
1007}
1008
Ben Hutchingsca0c88c2013-11-18 23:05:27 +00001009static int gfar_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
1010{
1011 struct hwtstamp_config config;
1012 struct gfar_private *priv = netdev_priv(netdev);
1013
1014 config.flags = 0;
1015 config.tx_type = priv->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
1016 config.rx_filter = (priv->hwts_rx_en ?
1017 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
1018
1019 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1020 -EFAULT : 0;
1021}
1022
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001023static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1024{
1025 struct gfar_private *priv = netdev_priv(dev);
1026
1027 if (!netif_running(dev))
1028 return -EINVAL;
1029
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001030 if (cmd == SIOCSHWTSTAMP)
Ben Hutchingsca0c88c2013-11-18 23:05:27 +00001031 return gfar_hwtstamp_set(dev, rq);
1032 if (cmd == SIOCGHWTSTAMP)
1033 return gfar_hwtstamp_get(dev, rq);
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001034
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001035 if (!priv->phydev)
1036 return -ENODEV;
1037
Richard Cochran28b04112010-07-17 08:48:55 +00001038 return phy_mii_ioctl(priv->phydev, rq, cmd);
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001039}
1040
Anton Vorontsov18294ad2009-11-04 12:53:00 +00001041static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar,
1042 u32 class)
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001043{
1044 u32 rqfpr = FPR_FILER_MASK;
1045 u32 rqfcr = 0x0;
1046
1047 rqfar--;
1048 rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001049 priv->ftp_rqfpr[rqfar] = rqfpr;
1050 priv->ftp_rqfcr[rqfar] = rqfcr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001051 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1052
1053 rqfar--;
1054 rqfcr = RQFCR_CMP_NOMATCH;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001055 priv->ftp_rqfpr[rqfar] = rqfpr;
1056 priv->ftp_rqfcr[rqfar] = rqfcr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001057 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1058
1059 rqfar--;
1060 rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND;
1061 rqfpr = class;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001062 priv->ftp_rqfcr[rqfar] = rqfcr;
1063 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001064 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1065
1066 rqfar--;
1067 rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND;
1068 rqfpr = class;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001069 priv->ftp_rqfcr[rqfar] = rqfcr;
1070 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001071 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1072
1073 return rqfar;
1074}
1075
1076static void gfar_init_filer_table(struct gfar_private *priv)
1077{
1078 int i = 0x0;
1079 u32 rqfar = MAX_FILER_IDX;
1080 u32 rqfcr = 0x0;
1081 u32 rqfpr = FPR_FILER_MASK;
1082
1083 /* Default rule */
1084 rqfcr = RQFCR_CMP_MATCH;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001085 priv->ftp_rqfcr[rqfar] = rqfcr;
1086 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001087 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1088
1089 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6);
1090 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP);
1091 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP);
1092 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4);
1093 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP);
1094 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP);
1095
Uwe Kleine-König85dd08e2010-06-11 12:16:55 +02001096 /* cur_filer_idx indicated the first non-masked rule */
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001097 priv->cur_filer_idx = rqfar;
1098
1099 /* Rest are masked rules */
1100 rqfcr = RQFCR_CMP_NOMATCH;
1101 for (i = 0; i < rqfar; i++) {
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001102 priv->ftp_rqfcr[i] = rqfcr;
1103 priv->ftp_rqfpr[i] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001104 gfar_write_filer(priv, i, rqfcr, rqfpr);
1105 }
1106}
1107
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001108#ifdef CONFIG_PPC
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001109static void __gfar_detect_errata_83xx(struct gfar_private *priv)
Anton Vorontsov7d350972010-06-30 06:39:12 +00001110{
Anton Vorontsov7d350972010-06-30 06:39:12 +00001111 unsigned int pvr = mfspr(SPRN_PVR);
1112 unsigned int svr = mfspr(SPRN_SVR);
1113 unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */
1114 unsigned int rev = svr & 0xffff;
1115
1116 /* MPC8313 Rev 2.0 and higher; All MPC837x */
1117 if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001118 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
Anton Vorontsov7d350972010-06-30 06:39:12 +00001119 priv->errata |= GFAR_ERRATA_74;
1120
Anton Vorontsovdeb90ea2010-06-30 06:39:13 +00001121 /* MPC8313 and MPC837x all rev */
1122 if ((pvr == 0x80850010 && mod == 0x80b0) ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001123 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
Anton Vorontsovdeb90ea2010-06-30 06:39:13 +00001124 priv->errata |= GFAR_ERRATA_76;
1125
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001126 /* MPC8313 Rev < 2.0 */
1127 if (pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020)
Alex Dubov4363c2fdd2011-03-16 17:57:13 +00001128 priv->errata |= GFAR_ERRATA_12;
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001129}
1130
1131static void __gfar_detect_errata_85xx(struct gfar_private *priv)
1132{
1133 unsigned int svr = mfspr(SPRN_SVR);
1134
1135 if ((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) == 0x20))
1136 priv->errata |= GFAR_ERRATA_12;
Claudiu Manoil53fad772013-10-09 20:20:42 +03001137 if (((SVR_SOC_VER(svr) == SVR_P2020) && (SVR_REV(svr) < 0x20)) ||
1138 ((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20)))
1139 priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001140}
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001141#endif
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001142
1143static void gfar_detect_errata(struct gfar_private *priv)
1144{
1145 struct device *dev = &priv->ofdev->dev;
1146
1147 /* no plans to fix */
1148 priv->errata |= GFAR_ERRATA_A002;
1149
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001150#ifdef CONFIG_PPC
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001151 if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2))
1152 __gfar_detect_errata_85xx(priv);
1153 else /* non-mpc85xx parts, i.e. e300 core based */
1154 __gfar_detect_errata_83xx(priv);
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001155#endif
Alex Dubov4363c2fdd2011-03-16 17:57:13 +00001156
Anton Vorontsov7d350972010-06-30 06:39:12 +00001157 if (priv->errata)
1158 dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
1159 priv->errata);
1160}
1161
Claudiu Manoil08511332014-02-24 12:13:45 +02001162void gfar_mac_reset(struct gfar_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Claudiu Manoil20862782014-02-17 12:53:14 +02001164 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Claudiu Manoila328ac92014-02-24 12:13:42 +02001165 u32 tempval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 /* Reset MAC layer */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001168 gfar_write(&regs->maccfg1, MACCFG1_SOFT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Andy Flemingb98ac702009-02-04 16:38:05 -08001170 /* We need to delay at least 3 TX clocks */
Claudiu Manoila328ac92014-02-24 12:13:42 +02001171 udelay(3);
Andy Flemingb98ac702009-02-04 16:38:05 -08001172
Claudiu Manoil23402bd2013-08-12 13:53:26 +03001173 /* the soft reset bit is not self-resetting, so we need to
1174 * clear it before resuming normal operation
1175 */
Claudiu Manoil20862782014-02-17 12:53:14 +02001176 gfar_write(&regs->maccfg1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Claudiu Manoila328ac92014-02-24 12:13:42 +02001178 udelay(3);
1179
Claudiu Manoil88302642014-02-24 12:13:43 +02001180 /* Compute rx_buff_size based on config flags */
1181 gfar_rx_buff_size_config(priv);
1182
1183 /* Initialize the max receive frame/buffer lengths */
1184 gfar_write(&regs->maxfrm, priv->rx_buffer_size);
Claudiu Manoila328ac92014-02-24 12:13:42 +02001185 gfar_write(&regs->mrblr, priv->rx_buffer_size);
1186
1187 /* Initialize the Minimum Frame Length Register */
1188 gfar_write(&regs->minflr, MINFLR_INIT_SETTINGS);
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 /* Initialize MACCFG2. */
Anton Vorontsov7d350972010-06-30 06:39:12 +00001191 tempval = MACCFG2_INIT_SETTINGS;
Claudiu Manoil88302642014-02-24 12:13:43 +02001192
1193 /* If the mtu is larger than the max size for standard
1194 * ethernet frames (ie, a jumbo frame), then set maccfg2
1195 * to allow huge frames, and to check the length
1196 */
1197 if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE ||
1198 gfar_has_errata(priv, GFAR_ERRATA_74))
Anton Vorontsov7d350972010-06-30 06:39:12 +00001199 tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK;
Claudiu Manoil88302642014-02-24 12:13:43 +02001200
Anton Vorontsov7d350972010-06-30 06:39:12 +00001201 gfar_write(&regs->maccfg2, tempval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Claudiu Manoila328ac92014-02-24 12:13:42 +02001203 /* Clear mac addr hash registers */
1204 gfar_write(&regs->igaddr0, 0);
1205 gfar_write(&regs->igaddr1, 0);
1206 gfar_write(&regs->igaddr2, 0);
1207 gfar_write(&regs->igaddr3, 0);
1208 gfar_write(&regs->igaddr4, 0);
1209 gfar_write(&regs->igaddr5, 0);
1210 gfar_write(&regs->igaddr6, 0);
1211 gfar_write(&regs->igaddr7, 0);
1212
1213 gfar_write(&regs->gaddr0, 0);
1214 gfar_write(&regs->gaddr1, 0);
1215 gfar_write(&regs->gaddr2, 0);
1216 gfar_write(&regs->gaddr3, 0);
1217 gfar_write(&regs->gaddr4, 0);
1218 gfar_write(&regs->gaddr5, 0);
1219 gfar_write(&regs->gaddr6, 0);
1220 gfar_write(&regs->gaddr7, 0);
1221
1222 if (priv->extended_hash)
1223 gfar_clear_exact_match(priv->ndev);
1224
1225 gfar_mac_rx_config(priv);
1226
1227 gfar_mac_tx_config(priv);
1228
1229 gfar_set_mac_address(priv->ndev);
1230
1231 gfar_set_multi(priv->ndev);
1232
1233 /* clear ievent and imask before configuring coalescing */
1234 gfar_ints_disable(priv);
1235
1236 /* Configure the coalescing support */
1237 gfar_configure_coalescing_all(priv);
1238}
1239
1240static void gfar_hw_init(struct gfar_private *priv)
1241{
1242 struct gfar __iomem *regs = priv->gfargrp[0].regs;
1243 u32 attrs;
1244
1245 /* Stop the DMA engine now, in case it was running before
1246 * (The firmware could have used it, and left it running).
1247 */
1248 gfar_halt(priv);
1249
1250 gfar_mac_reset(priv);
1251
1252 /* Zero out the rmon mib registers if it has them */
1253 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
1254 memset_io(&(regs->rmon), 0, sizeof(struct rmon_mib));
1255
1256 /* Mask off the CAM interrupts */
1257 gfar_write(&regs->rmon.cam1, 0xffffffff);
1258 gfar_write(&regs->rmon.cam2, 0xffffffff);
1259 }
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 /* Initialize ECNTRL */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001262 gfar_write(&regs->ecntrl, ECNTRL_INIT_SETTINGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Claudiu Manoil34018fd2014-02-17 12:53:15 +02001264 /* Set the extraction length and index */
1265 attrs = ATTRELI_EL(priv->rx_stash_size) |
1266 ATTRELI_EI(priv->rx_stash_index);
1267
1268 gfar_write(&regs->attreli, attrs);
1269
1270 /* Start with defaults, and add stashing
1271 * depending on driver parameters
1272 */
1273 attrs = ATTR_INIT_SETTINGS;
1274
1275 if (priv->bd_stash_en)
1276 attrs |= ATTR_BDSTASH;
1277
1278 if (priv->rx_stash_size != 0)
1279 attrs |= ATTR_BUFSTASH;
1280
1281 gfar_write(&regs->attr, attrs);
1282
1283 /* FIFO configs */
1284 gfar_write(&regs->fifo_tx_thr, DEFAULT_FIFO_TX_THR);
1285 gfar_write(&regs->fifo_tx_starve, DEFAULT_FIFO_TX_STARVE);
1286 gfar_write(&regs->fifo_tx_starve_shutoff, DEFAULT_FIFO_TX_STARVE_OFF);
1287
Claudiu Manoil20862782014-02-17 12:53:14 +02001288 /* Program the interrupt steering regs, only for MG devices */
1289 if (priv->num_grps > 1)
1290 gfar_write_isrg(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001291}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Xiubo Li898157e2014-06-04 16:49:16 +08001293static void gfar_init_addr_hash_table(struct gfar_private *priv)
Claudiu Manoil20862782014-02-17 12:53:14 +02001294{
1295 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001296
Andy Flemingb31a1d82008-12-16 15:29:15 -08001297 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
Kumar Gala0bbaf062005-06-20 10:54:21 -05001298 priv->extended_hash = 1;
1299 priv->hash_width = 9;
1300
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001301 priv->hash_regs[0] = &regs->igaddr0;
1302 priv->hash_regs[1] = &regs->igaddr1;
1303 priv->hash_regs[2] = &regs->igaddr2;
1304 priv->hash_regs[3] = &regs->igaddr3;
1305 priv->hash_regs[4] = &regs->igaddr4;
1306 priv->hash_regs[5] = &regs->igaddr5;
1307 priv->hash_regs[6] = &regs->igaddr6;
1308 priv->hash_regs[7] = &regs->igaddr7;
1309 priv->hash_regs[8] = &regs->gaddr0;
1310 priv->hash_regs[9] = &regs->gaddr1;
1311 priv->hash_regs[10] = &regs->gaddr2;
1312 priv->hash_regs[11] = &regs->gaddr3;
1313 priv->hash_regs[12] = &regs->gaddr4;
1314 priv->hash_regs[13] = &regs->gaddr5;
1315 priv->hash_regs[14] = &regs->gaddr6;
1316 priv->hash_regs[15] = &regs->gaddr7;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001317
1318 } else {
1319 priv->extended_hash = 0;
1320 priv->hash_width = 8;
1321
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001322 priv->hash_regs[0] = &regs->gaddr0;
1323 priv->hash_regs[1] = &regs->gaddr1;
1324 priv->hash_regs[2] = &regs->gaddr2;
1325 priv->hash_regs[3] = &regs->gaddr3;
1326 priv->hash_regs[4] = &regs->gaddr4;
1327 priv->hash_regs[5] = &regs->gaddr5;
1328 priv->hash_regs[6] = &regs->gaddr6;
1329 priv->hash_regs[7] = &regs->gaddr7;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001330 }
Claudiu Manoil20862782014-02-17 12:53:14 +02001331}
1332
1333/* Set up the ethernet device structure, private data,
1334 * and anything else we need before we start
1335 */
1336static int gfar_probe(struct platform_device *ofdev)
1337{
1338 struct net_device *dev = NULL;
1339 struct gfar_private *priv = NULL;
1340 int err = 0, i;
1341
1342 err = gfar_of_init(ofdev, &dev);
1343
1344 if (err)
1345 return err;
1346
1347 priv = netdev_priv(dev);
1348 priv->ndev = dev;
1349 priv->ofdev = ofdev;
1350 priv->dev = &ofdev->dev;
1351 SET_NETDEV_DEV(dev, &ofdev->dev);
1352
1353 spin_lock_init(&priv->bflock);
1354 INIT_WORK(&priv->reset_task, gfar_reset_task);
1355
1356 platform_set_drvdata(ofdev, priv);
1357
1358 gfar_detect_errata(priv);
1359
Claudiu Manoil20862782014-02-17 12:53:14 +02001360 /* Set the dev->base_addr to the gfar reg region */
1361 dev->base_addr = (unsigned long) priv->gfargrp[0].regs;
1362
1363 /* Fill in the dev structure */
1364 dev->watchdog_timeo = TX_TIMEOUT;
1365 dev->mtu = 1500;
1366 dev->netdev_ops = &gfar_netdev_ops;
1367 dev->ethtool_ops = &gfar_ethtool_ops;
1368
1369 /* Register for napi ...We are registering NAPI for each grp */
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02001370 for (i = 0; i < priv->num_grps; i++) {
1371 if (priv->poll_mode == GFAR_SQ_POLLING) {
1372 netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
1373 gfar_poll_rx_sq, GFAR_DEV_WEIGHT);
1374 netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
1375 gfar_poll_tx_sq, 2);
1376 } else {
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02001377 netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
1378 gfar_poll_rx, GFAR_DEV_WEIGHT);
1379 netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
1380 gfar_poll_tx, 2);
1381 }
1382 }
Claudiu Manoil20862782014-02-17 12:53:14 +02001383
1384 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
1385 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
1386 NETIF_F_RXCSUM;
1387 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG |
1388 NETIF_F_RXCSUM | NETIF_F_HIGHDMA;
1389 }
1390
1391 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
1392 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX |
1393 NETIF_F_HW_VLAN_CTAG_RX;
1394 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1395 }
1396
1397 gfar_init_addr_hash_table(priv);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001398
Claudiu Manoil532c37b2014-02-17 12:53:16 +02001399 /* Insert receive time stamps into padding alignment bytes */
1400 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
1401 priv->padding = 8;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001402
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001403 if (dev->features & NETIF_F_IP_CSUM ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001404 priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
Wu Jiajun-B06378bee9e582012-05-21 23:00:48 +00001405 dev->needed_headroom = GMAC_FCB_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001409 /* Initializing some of the rx/tx queue level parameters */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001410 for (i = 0; i < priv->num_tx_queues; i++) {
1411 priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE;
1412 priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE;
1413 priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE;
1414 priv->tx_queue[i]->txic = DEFAULT_TXIC;
1415 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001416
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001417 for (i = 0; i < priv->num_rx_queues; i++) {
1418 priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE;
1419 priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE;
1420 priv->rx_queue[i]->rxic = DEFAULT_RXIC;
1421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Jan Ceuleers0977f812012-06-05 03:42:12 +00001423 /* always enable rx filer */
Sebastian Poehn4aa3a712011-06-20 13:57:59 -07001424 priv->rx_filer_enable = 1;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001425 /* Enable most messages by default */
1426 priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
Claudiu Manoilb98b8ba2012-09-23 22:39:08 +00001427 /* use pritority h/w tx queue scheduling for single queue devices */
1428 if (priv->num_tx_queues == 1)
1429 priv->prio_sched_en = 1;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001430
Claudiu Manoil08511332014-02-24 12:13:45 +02001431 set_bit(GFAR_DOWN, &priv->state);
1432
Claudiu Manoila328ac92014-02-24 12:13:42 +02001433 gfar_hw_init(priv);
Trent Piephod3eab822008-10-02 11:12:24 +00001434
Fabio Estevamd4c642e2014-06-03 19:55:38 -03001435 /* Carrier starts down, phylib will bring it up */
1436 netif_carrier_off(dev);
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 err = register_netdev(dev);
1439
1440 if (err) {
Joe Perches59deab22011-06-14 08:57:47 +00001441 pr_err("%s: Cannot register net device, aborting\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 goto register_fail;
1443 }
1444
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08001445 device_init_wakeup(&dev->dev,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001446 priv->device_flags &
1447 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08001448
Dai Harukic50a5d92008-12-17 16:51:32 -08001449 /* fill out IRQ number and name fields */
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001450 for (i = 0; i < priv->num_grps; i++) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001451 struct gfar_priv_grp *grp = &priv->gfargrp[i];
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001452 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001453 sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001454 dev->name, "_g", '0' + i, "_tx");
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001455 sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001456 dev->name, "_g", '0' + i, "_rx");
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001457 sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001458 dev->name, "_g", '0' + i, "_er");
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001459 } else
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001460 strcpy(gfar_irq(grp, TX)->name, dev->name);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001461 }
Dai Harukic50a5d92008-12-17 16:51:32 -08001462
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001463 /* Initialize the filer table */
1464 gfar_init_filer_table(priv);
1465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 /* Print out the device info */
Joe Perches59deab22011-06-14 08:57:47 +00001467 netdev_info(dev, "mac: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Jan Ceuleers0977f812012-06-05 03:42:12 +00001469 /* Even more device info helps when determining which kernel
1470 * provided which set of benchmarks.
1471 */
Joe Perches59deab22011-06-14 08:57:47 +00001472 netdev_info(dev, "Running with NAPI enabled\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001473 for (i = 0; i < priv->num_rx_queues; i++)
Joe Perches59deab22011-06-14 08:57:47 +00001474 netdev_info(dev, "RX BD ring size for Q[%d]: %d\n",
1475 i, priv->rx_queue[i]->rx_ring_size);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001476 for (i = 0; i < priv->num_tx_queues; i++)
Joe Perches59deab22011-06-14 08:57:47 +00001477 netdev_info(dev, "TX BD ring size for Q[%d]: %d\n",
1478 i, priv->tx_queue[i]->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 return 0;
1481
1482register_fail:
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001483 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001484 gfar_free_rx_queues(priv);
1485 gfar_free_tx_queues(priv);
Uwe Kleine-König888c88b2014-08-07 21:20:12 +02001486 of_node_put(priv->phy_node);
1487 of_node_put(priv->tbi_node);
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001488 free_gfar_dev(priv);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001489 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Grant Likely2dc11582010-08-06 09:25:50 -06001492static int gfar_remove(struct platform_device *ofdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Jingoo Han8513fbd2013-05-23 00:52:31 +00001494 struct gfar_private *priv = platform_get_drvdata(ofdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Uwe Kleine-König888c88b2014-08-07 21:20:12 +02001496 of_node_put(priv->phy_node);
1497 of_node_put(priv->tbi_node);
Grant Likelyfe192a42009-04-25 12:53:12 +00001498
David S. Millerd9d8e042009-09-06 01:41:02 -07001499 unregister_netdev(priv->ndev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001500 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001501 gfar_free_rx_queues(priv);
1502 gfar_free_tx_queues(priv);
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001503 free_gfar_dev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 return 0;
1506}
1507
Scott Woodd87eb122008-07-11 18:04:45 -05001508#ifdef CONFIG_PM
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001509
1510static int gfar_suspend(struct device *dev)
Scott Woodd87eb122008-07-11 18:04:45 -05001511{
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001512 struct gfar_private *priv = dev_get_drvdata(dev);
1513 struct net_device *ndev = priv->ndev;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001514 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001515 unsigned long flags;
1516 u32 tempval;
1517
1518 int magic_packet = priv->wol_en &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001519 (priv->device_flags &
1520 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Scott Woodd87eb122008-07-11 18:04:45 -05001521
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001522 netif_device_detach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001523
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001524 if (netif_running(ndev)) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001525
1526 local_irq_save(flags);
1527 lock_tx_qs(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001528
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001529 gfar_halt_nodisable(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001530
1531 /* Disable Tx, and Rx if wake-on-LAN is disabled. */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001532 tempval = gfar_read(&regs->maccfg1);
Scott Woodd87eb122008-07-11 18:04:45 -05001533
1534 tempval &= ~MACCFG1_TX_EN;
1535
1536 if (!magic_packet)
1537 tempval &= ~MACCFG1_RX_EN;
1538
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001539 gfar_write(&regs->maccfg1, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001540
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001541 unlock_tx_qs(priv);
1542 local_irq_restore(flags);
Scott Woodd87eb122008-07-11 18:04:45 -05001543
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001544 disable_napi(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001545
1546 if (magic_packet) {
1547 /* Enable interrupt on Magic Packet */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001548 gfar_write(&regs->imask, IMASK_MAG);
Scott Woodd87eb122008-07-11 18:04:45 -05001549
1550 /* Enable Magic Packet mode */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001551 tempval = gfar_read(&regs->maccfg2);
Scott Woodd87eb122008-07-11 18:04:45 -05001552 tempval |= MACCFG2_MPEN;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001553 gfar_write(&regs->maccfg2, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001554 } else {
1555 phy_stop(priv->phydev);
1556 }
1557 }
1558
1559 return 0;
1560}
1561
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001562static int gfar_resume(struct device *dev)
Scott Woodd87eb122008-07-11 18:04:45 -05001563{
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001564 struct gfar_private *priv = dev_get_drvdata(dev);
1565 struct net_device *ndev = priv->ndev;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001566 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001567 unsigned long flags;
1568 u32 tempval;
1569 int magic_packet = priv->wol_en &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001570 (priv->device_flags &
1571 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Scott Woodd87eb122008-07-11 18:04:45 -05001572
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001573 if (!netif_running(ndev)) {
1574 netif_device_attach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001575 return 0;
1576 }
1577
1578 if (!magic_packet && priv->phydev)
1579 phy_start(priv->phydev);
1580
1581 /* Disable Magic Packet mode, in case something
1582 * else woke us up.
1583 */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001584 local_irq_save(flags);
1585 lock_tx_qs(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001586
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001587 tempval = gfar_read(&regs->maccfg2);
Scott Woodd87eb122008-07-11 18:04:45 -05001588 tempval &= ~MACCFG2_MPEN;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001589 gfar_write(&regs->maccfg2, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001590
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001591 gfar_start(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001592
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001593 unlock_tx_qs(priv);
1594 local_irq_restore(flags);
Scott Woodd87eb122008-07-11 18:04:45 -05001595
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001596 netif_device_attach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001597
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001598 enable_napi(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001599
1600 return 0;
1601}
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001602
1603static int gfar_restore(struct device *dev)
1604{
1605 struct gfar_private *priv = dev_get_drvdata(dev);
1606 struct net_device *ndev = priv->ndev;
1607
Wang Dongsheng103cdd12012-11-09 04:43:51 +00001608 if (!netif_running(ndev)) {
1609 netif_device_attach(ndev);
1610
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001611 return 0;
Wang Dongsheng103cdd12012-11-09 04:43:51 +00001612 }
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001613
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001614 if (gfar_init_bds(ndev)) {
1615 free_skb_resources(priv);
1616 return -ENOMEM;
1617 }
1618
Claudiu Manoila328ac92014-02-24 12:13:42 +02001619 gfar_mac_reset(priv);
1620
1621 gfar_init_tx_rx_base(priv);
1622
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001623 gfar_start(priv);
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001624
1625 priv->oldlink = 0;
1626 priv->oldspeed = 0;
1627 priv->oldduplex = -1;
1628
1629 if (priv->phydev)
1630 phy_start(priv->phydev);
1631
1632 netif_device_attach(ndev);
Anton Vorontsov5ea681d2009-11-10 14:11:05 +00001633 enable_napi(priv);
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001634
1635 return 0;
1636}
1637
1638static struct dev_pm_ops gfar_pm_ops = {
1639 .suspend = gfar_suspend,
1640 .resume = gfar_resume,
1641 .freeze = gfar_suspend,
1642 .thaw = gfar_resume,
1643 .restore = gfar_restore,
1644};
1645
1646#define GFAR_PM_OPS (&gfar_pm_ops)
1647
Scott Woodd87eb122008-07-11 18:04:45 -05001648#else
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001649
1650#define GFAR_PM_OPS NULL
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001651
Scott Woodd87eb122008-07-11 18:04:45 -05001652#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001654/* Reads the controller's registers to determine what interface
1655 * connects it to the PHY.
1656 */
1657static phy_interface_t gfar_get_interface(struct net_device *dev)
1658{
1659 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001660 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001661 u32 ecntrl;
1662
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001663 ecntrl = gfar_read(&regs->ecntrl);
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001664
1665 if (ecntrl & ECNTRL_SGMII_MODE)
1666 return PHY_INTERFACE_MODE_SGMII;
1667
1668 if (ecntrl & ECNTRL_TBI_MODE) {
1669 if (ecntrl & ECNTRL_REDUCED_MODE)
1670 return PHY_INTERFACE_MODE_RTBI;
1671 else
1672 return PHY_INTERFACE_MODE_TBI;
1673 }
1674
1675 if (ecntrl & ECNTRL_REDUCED_MODE) {
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001676 if (ecntrl & ECNTRL_REDUCED_MII_MODE) {
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001677 return PHY_INTERFACE_MODE_RMII;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001678 }
Andy Fleming7132ab72007-07-11 11:43:07 -05001679 else {
Andy Flemingb31a1d82008-12-16 15:29:15 -08001680 phy_interface_t interface = priv->interface;
Andy Fleming7132ab72007-07-11 11:43:07 -05001681
Jan Ceuleers0977f812012-06-05 03:42:12 +00001682 /* This isn't autodetected right now, so it must
Andy Fleming7132ab72007-07-11 11:43:07 -05001683 * be set by the device tree or platform code.
1684 */
1685 if (interface == PHY_INTERFACE_MODE_RGMII_ID)
1686 return PHY_INTERFACE_MODE_RGMII_ID;
1687
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001688 return PHY_INTERFACE_MODE_RGMII;
Andy Fleming7132ab72007-07-11 11:43:07 -05001689 }
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001690 }
1691
Andy Flemingb31a1d82008-12-16 15:29:15 -08001692 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001693 return PHY_INTERFACE_MODE_GMII;
1694
1695 return PHY_INTERFACE_MODE_MII;
1696}
1697
1698
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001699/* Initializes driver's PHY state, and attaches to the PHY.
1700 * Returns 0 on success.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 */
1702static int init_phy(struct net_device *dev)
1703{
1704 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001705 uint gigabit_support =
Andy Flemingb31a1d82008-12-16 15:29:15 -08001706 priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
Claudiu Manoil23402bd2013-08-12 13:53:26 +03001707 GFAR_SUPPORTED_GBIT : 0;
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001708 phy_interface_t interface;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 priv->oldlink = 0;
1711 priv->oldspeed = 0;
1712 priv->oldduplex = -1;
1713
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001714 interface = gfar_get_interface(dev);
1715
Anton Vorontsov1db780f2009-07-16 21:31:42 +00001716 priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
1717 interface);
Anton Vorontsov1db780f2009-07-16 21:31:42 +00001718 if (!priv->phydev) {
1719 dev_err(&dev->dev, "could not attach to PHY\n");
1720 return -ENODEV;
Grant Likelyfe192a42009-04-25 12:53:12 +00001721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Kapil Junejad3c12872007-05-11 18:25:11 -05001723 if (interface == PHY_INTERFACE_MODE_SGMII)
1724 gfar_configure_serdes(dev);
1725
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001726 /* Remove any features not supported by the controller */
Grant Likelyfe192a42009-04-25 12:53:12 +00001727 priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
1728 priv->phydev->advertising = priv->phydev->supported;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Pavaluca Matei-B46610cf987af2014-10-27 10:42:42 +02001730 /* Add support for flow control, but don't advertise it by default */
1731 priv->phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
Jan Ceuleers0977f812012-06-05 03:42:12 +00001736/* Initialize TBI PHY interface for communicating with the
Paul Gortmakerd0313582008-04-17 00:08:10 -04001737 * SERDES lynx PHY on the chip. We communicate with this PHY
1738 * through the MDIO bus on each controller, treating it as a
1739 * "normal" PHY at the address found in the TBIPA register. We assume
1740 * that the TBIPA register is valid. Either the MDIO bus code will set
1741 * it to a value that doesn't conflict with other PHYs on the bus, or the
1742 * value doesn't matter, as there are no other PHYs on the bus.
1743 */
Kapil Junejad3c12872007-05-11 18:25:11 -05001744static void gfar_configure_serdes(struct net_device *dev)
1745{
1746 struct gfar_private *priv = netdev_priv(dev);
Grant Likelyfe192a42009-04-25 12:53:12 +00001747 struct phy_device *tbiphy;
Trent Piephoc1324192008-10-30 18:17:06 -07001748
Grant Likelyfe192a42009-04-25 12:53:12 +00001749 if (!priv->tbi_node) {
1750 dev_warn(&dev->dev, "error: SGMII mode requires that the "
1751 "device tree specify a tbi-handle\n");
1752 return;
1753 }
1754
1755 tbiphy = of_phy_find_device(priv->tbi_node);
1756 if (!tbiphy) {
1757 dev_err(&dev->dev, "error: Could not get TBI device\n");
Andy Flemingb31a1d82008-12-16 15:29:15 -08001758 return;
1759 }
Kapil Junejad3c12872007-05-11 18:25:11 -05001760
Jan Ceuleers0977f812012-06-05 03:42:12 +00001761 /* If the link is already up, we must already be ok, and don't need to
Trent Piephobdb59f92008-10-30 18:17:07 -07001762 * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
1763 * everything for us? Resetting it takes the link down and requires
1764 * several seconds for it to come back.
1765 */
Grant Likelyfe192a42009-04-25 12:53:12 +00001766 if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
Andy Flemingb31a1d82008-12-16 15:29:15 -08001767 return;
Kapil Junejad3c12872007-05-11 18:25:11 -05001768
Paul Gortmakerd0313582008-04-17 00:08:10 -04001769 /* Single clk mode, mii mode off(for serdes communication) */
Grant Likelyfe192a42009-04-25 12:53:12 +00001770 phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
Kapil Junejad3c12872007-05-11 18:25:11 -05001771
Grant Likelyfe192a42009-04-25 12:53:12 +00001772 phy_write(tbiphy, MII_ADVERTISE,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001773 ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
1774 ADVERTISE_1000XPSE_ASYM);
Kapil Junejad3c12872007-05-11 18:25:11 -05001775
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001776 phy_write(tbiphy, MII_BMCR,
1777 BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX |
1778 BMCR_SPEED1000);
Kapil Junejad3c12872007-05-11 18:25:11 -05001779}
1780
Anton Vorontsov511d9342010-06-30 06:39:15 +00001781static int __gfar_is_rx_idle(struct gfar_private *priv)
1782{
1783 u32 res;
1784
Jan Ceuleers0977f812012-06-05 03:42:12 +00001785 /* Normaly TSEC should not hang on GRS commands, so we should
Anton Vorontsov511d9342010-06-30 06:39:15 +00001786 * actually wait for IEVENT_GRSC flag.
1787 */
Claudiu Manoilad3660c2013-10-09 20:20:40 +03001788 if (!gfar_has_errata(priv, GFAR_ERRATA_A002))
Anton Vorontsov511d9342010-06-30 06:39:15 +00001789 return 0;
1790
Jan Ceuleers0977f812012-06-05 03:42:12 +00001791 /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are
Anton Vorontsov511d9342010-06-30 06:39:15 +00001792 * the same as bits 23-30, the eTSEC Rx is assumed to be idle
1793 * and the Rx can be safely reset.
1794 */
1795 res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c);
1796 res &= 0x7f807f80;
1797 if ((res & 0xffff) == (res >> 16))
1798 return 1;
1799
1800 return 0;
1801}
Kumar Gala0bbaf062005-06-20 10:54:21 -05001802
1803/* Halt the receive and transmit queues */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001804static void gfar_halt_nodisable(struct gfar_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
Claudiu Manoilefeddce2014-02-17 12:53:17 +02001806 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 u32 tempval;
Claudiu Manoila4feee82014-10-07 10:44:34 +03001808 unsigned int timeout;
1809 int stopped;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Claudiu Manoilefeddce2014-02-17 12:53:17 +02001811 gfar_ints_disable(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Claudiu Manoila4feee82014-10-07 10:44:34 +03001813 if (gfar_is_dma_stopped(priv))
1814 return;
1815
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 /* Stop the DMA, and wait for it to stop */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001817 tempval = gfar_read(&regs->dmactrl);
Claudiu Manoila4feee82014-10-07 10:44:34 +03001818 tempval |= (DMACTRL_GRS | DMACTRL_GTS);
1819 gfar_write(&regs->dmactrl, tempval);
Anton Vorontsov511d9342010-06-30 06:39:15 +00001820
Claudiu Manoila4feee82014-10-07 10:44:34 +03001821retry:
1822 timeout = 1000;
1823 while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) {
1824 cpu_relax();
1825 timeout--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 }
Claudiu Manoila4feee82014-10-07 10:44:34 +03001827
1828 if (!timeout)
1829 stopped = gfar_is_dma_stopped(priv);
1830
1831 if (!stopped && !gfar_is_rx_dma_stopped(priv) &&
1832 !__gfar_is_rx_idle(priv))
1833 goto retry;
Scott Woodd87eb122008-07-11 18:04:45 -05001834}
Scott Woodd87eb122008-07-11 18:04:45 -05001835
1836/* Halt the receive and transmit queues */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001837void gfar_halt(struct gfar_private *priv)
Scott Woodd87eb122008-07-11 18:04:45 -05001838{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001839 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001840 u32 tempval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001842 /* Dissable the Rx/Tx hw queues */
1843 gfar_write(&regs->rqueue, 0);
1844 gfar_write(&regs->tqueue, 0);
Scott Wood2a54adc2008-08-12 15:10:46 -05001845
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001846 mdelay(10);
1847
1848 gfar_halt_nodisable(priv);
1849
1850 /* Disable Rx/Tx DMA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 tempval = gfar_read(&regs->maccfg1);
1852 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
1853 gfar_write(&regs->maccfg1, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001854}
1855
1856void stop_gfar(struct net_device *dev)
1857{
1858 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001859
Claudiu Manoil08511332014-02-24 12:13:45 +02001860 netif_tx_stop_all_queues(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001861
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001862 smp_mb__before_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02001863 set_bit(GFAR_DOWN, &priv->state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001864 smp_mb__after_atomic();
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001865
Claudiu Manoil08511332014-02-24 12:13:45 +02001866 disable_napi(priv);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001867
Claudiu Manoil08511332014-02-24 12:13:45 +02001868 /* disable ints and gracefully shut down Rx/Tx DMA */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001869 gfar_halt(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Claudiu Manoil08511332014-02-24 12:13:45 +02001871 phy_stop(priv->phydev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 free_skb_resources(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001876static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 struct txbd8 *txbdp;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001879 struct gfar_private *priv = netdev_priv(tx_queue->dev);
Dai Haruki4669bc92008-12-17 16:51:04 -08001880 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001882 txbdp = tx_queue->tx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001884 for (i = 0; i < tx_queue->tx_ring_size; i++) {
1885 if (!tx_queue->tx_skbuff[i])
Dai Haruki4669bc92008-12-17 16:51:04 -08001886 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Claudiu Manoila7312d52015-03-13 10:36:28 +02001888 dma_unmap_single(priv->dev, be32_to_cpu(txbdp->bufPtr),
1889 be16_to_cpu(txbdp->length), DMA_TO_DEVICE);
Dai Haruki4669bc92008-12-17 16:51:04 -08001890 txbdp->lstatus = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001891 for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001892 j++) {
Dai Haruki4669bc92008-12-17 16:51:04 -08001893 txbdp++;
Claudiu Manoila7312d52015-03-13 10:36:28 +02001894 dma_unmap_page(priv->dev, be32_to_cpu(txbdp->bufPtr),
1895 be16_to_cpu(txbdp->length),
1896 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Andy Flemingad5da7a2008-05-07 13:20:55 -05001898 txbdp++;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001899 dev_kfree_skb_any(tx_queue->tx_skbuff[i]);
1900 tx_queue->tx_skbuff[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001902 kfree(tx_queue->tx_skbuff);
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001903 tx_queue->tx_skbuff = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001904}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001906static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
1907{
1908 struct rxbd8 *rxbdp;
1909 struct gfar_private *priv = netdev_priv(rx_queue->dev);
1910 int i;
1911
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001912 rxbdp = rx_queue->rx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001914 for (i = 0; i < rx_queue->rx_ring_size; i++) {
1915 if (rx_queue->rx_skbuff[i]) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02001916 dma_unmap_single(priv->dev, be32_to_cpu(rxbdp->bufPtr),
Claudiu Manoil369ec162013-02-14 05:00:02 +00001917 priv->rx_buffer_size,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001918 DMA_FROM_DEVICE);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001919 dev_kfree_skb_any(rx_queue->rx_skbuff[i]);
1920 rx_queue->rx_skbuff[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 }
Anton Vorontsove69edd22009-10-12 06:00:30 +00001922 rxbdp->lstatus = 0;
1923 rxbdp->bufPtr = 0;
1924 rxbdp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001926 kfree(rx_queue->rx_skbuff);
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001927 rx_queue->rx_skbuff = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001928}
Anton Vorontsove69edd22009-10-12 06:00:30 +00001929
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001930/* If there are any tx skbs or rx skbs still around, free them.
Jan Ceuleers0977f812012-06-05 03:42:12 +00001931 * Then free tx_skbuff and rx_skbuff
1932 */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001933static void free_skb_resources(struct gfar_private *priv)
1934{
1935 struct gfar_priv_tx_q *tx_queue = NULL;
1936 struct gfar_priv_rx_q *rx_queue = NULL;
1937 int i;
1938
1939 /* Go through all the buffer descriptors and free their data buffers */
1940 for (i = 0; i < priv->num_tx_queues; i++) {
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001941 struct netdev_queue *txq;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001942
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001943 tx_queue = priv->tx_queue[i];
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001944 txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001945 if (tx_queue->tx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001946 free_skb_tx_queue(tx_queue);
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001947 netdev_tx_reset_queue(txq);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001948 }
1949
1950 for (i = 0; i < priv->num_rx_queues; i++) {
1951 rx_queue = priv->rx_queue[i];
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001952 if (rx_queue->rx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001953 free_skb_rx_queue(rx_queue);
1954 }
1955
Claudiu Manoil369ec162013-02-14 05:00:02 +00001956 dma_free_coherent(priv->dev,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001957 sizeof(struct txbd8) * priv->total_tx_ring_size +
1958 sizeof(struct rxbd8) * priv->total_rx_ring_size,
1959 priv->tx_queue[0]->tx_bd_base,
1960 priv->tx_queue[0]->tx_bd_dma_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
1962
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001963void gfar_start(struct gfar_private *priv)
Kumar Gala0bbaf062005-06-20 10:54:21 -05001964{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001965 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001966 u32 tempval;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001967 int i = 0;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001968
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001969 /* Enable Rx/Tx hw queues */
1970 gfar_write(&regs->rqueue, priv->rqueue);
1971 gfar_write(&regs->tqueue, priv->tqueue);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001972
1973 /* Initialize DMACTRL to have WWR and WOP */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001974 tempval = gfar_read(&regs->dmactrl);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001975 tempval |= DMACTRL_INIT_SETTINGS;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001976 gfar_write(&regs->dmactrl, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001977
Kumar Gala0bbaf062005-06-20 10:54:21 -05001978 /* Make sure we aren't stopped */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001979 tempval = gfar_read(&regs->dmactrl);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001980 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001981 gfar_write(&regs->dmactrl, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001982
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001983 for (i = 0; i < priv->num_grps; i++) {
1984 regs = priv->gfargrp[i].regs;
1985 /* Clear THLT/RHLT, so that the DMA starts polling now */
1986 gfar_write(&regs->tstat, priv->gfargrp[i].tstat);
1987 gfar_write(&regs->rstat, priv->gfargrp[i].rstat);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001988 }
Dai Haruki12dea572008-12-16 15:30:20 -08001989
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001990 /* Enable Rx/Tx DMA */
1991 tempval = gfar_read(&regs->maccfg1);
1992 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
1993 gfar_write(&regs->maccfg1, tempval);
1994
Claudiu Manoilefeddce2014-02-17 12:53:17 +02001995 gfar_ints_enable(priv);
1996
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001997 priv->ndev->trans_start = jiffies; /* prevent tx timeout */
Kumar Gala0bbaf062005-06-20 10:54:21 -05001998}
1999
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002000static void free_grp_irqs(struct gfar_priv_grp *grp)
2001{
2002 free_irq(gfar_irq(grp, TX)->irq, grp);
2003 free_irq(gfar_irq(grp, RX)->irq, grp);
2004 free_irq(gfar_irq(grp, ER)->irq, grp);
2005}
2006
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002007static int register_grp_irqs(struct gfar_priv_grp *grp)
2008{
2009 struct gfar_private *priv = grp->priv;
2010 struct net_device *dev = priv->ndev;
Anton Vorontsovccc05c62009-10-12 06:00:26 +00002011 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 /* If the device has multiple interrupts, register for
Jan Ceuleers0977f812012-06-05 03:42:12 +00002014 * them. Otherwise, only register for the one
2015 */
Andy Flemingb31a1d82008-12-16 15:29:15 -08002016 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Kumar Gala0bbaf062005-06-20 10:54:21 -05002017 /* Install our interrupt handlers for Error,
Jan Ceuleers0977f812012-06-05 03:42:12 +00002018 * Transmit, and Receive
2019 */
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002020 err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0,
2021 gfar_irq(grp, ER)->name, grp);
2022 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002023 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002024 gfar_irq(grp, ER)->irq);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002025
Julia Lawall2145f1a2010-08-05 10:26:20 +00002026 goto err_irq_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 }
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002028 err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0,
2029 gfar_irq(grp, TX)->name, grp);
2030 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002031 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002032 gfar_irq(grp, TX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 goto tx_irq_fail;
2034 }
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002035 err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0,
2036 gfar_irq(grp, RX)->name, grp);
2037 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002038 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002039 gfar_irq(grp, RX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 goto rx_irq_fail;
2041 }
2042 } else {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002043 err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0,
2044 gfar_irq(grp, TX)->name, grp);
2045 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002046 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002047 gfar_irq(grp, TX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 goto err_irq_fail;
2049 }
2050 }
2051
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002052 return 0;
2053
2054rx_irq_fail:
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002055 free_irq(gfar_irq(grp, TX)->irq, grp);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002056tx_irq_fail:
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002057 free_irq(gfar_irq(grp, ER)->irq, grp);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002058err_irq_fail:
2059 return err;
2060
2061}
2062
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002063static void gfar_free_irq(struct gfar_private *priv)
2064{
2065 int i;
2066
2067 /* Free the IRQs */
2068 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
2069 for (i = 0; i < priv->num_grps; i++)
2070 free_grp_irqs(&priv->gfargrp[i]);
2071 } else {
2072 for (i = 0; i < priv->num_grps; i++)
2073 free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq,
2074 &priv->gfargrp[i]);
2075 }
2076}
2077
2078static int gfar_request_irq(struct gfar_private *priv)
2079{
2080 int err, i, j;
2081
2082 for (i = 0; i < priv->num_grps; i++) {
2083 err = register_grp_irqs(&priv->gfargrp[i]);
2084 if (err) {
2085 for (j = 0; j < i; j++)
2086 free_grp_irqs(&priv->gfargrp[j]);
2087 return err;
2088 }
2089 }
2090
2091 return 0;
2092}
2093
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002094/* Bring the controller up and running */
2095int startup_gfar(struct net_device *ndev)
2096{
2097 struct gfar_private *priv = netdev_priv(ndev);
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002098 int err;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002099
Claudiu Manoila328ac92014-02-24 12:13:42 +02002100 gfar_mac_reset(priv);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002101
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002102 err = gfar_alloc_skb_resources(ndev);
2103 if (err)
2104 return err;
2105
Claudiu Manoila328ac92014-02-24 12:13:42 +02002106 gfar_init_tx_rx_base(priv);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002107
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002108 smp_mb__before_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02002109 clear_bit(GFAR_DOWN, &priv->state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002110 smp_mb__after_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02002111
2112 /* Start Rx/Tx DMA and enable the interrupts */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02002113 gfar_start(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Anton Vorontsov826aa4a2009-10-12 06:00:34 +00002115 phy_start(priv->phydev);
2116
Claudiu Manoil08511332014-02-24 12:13:45 +02002117 enable_napi(priv);
2118
2119 netif_tx_wake_all_queues(ndev);
2120
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122}
2123
Jan Ceuleers0977f812012-06-05 03:42:12 +00002124/* Called when something needs to use the ethernet device
2125 * Returns 0 for success.
2126 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127static int gfar_enet_open(struct net_device *dev)
2128{
Li Yang94e8cc32007-10-12 21:53:51 +08002129 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 int err;
2131
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 err = init_phy(dev);
Claudiu Manoil08511332014-02-24 12:13:45 +02002133 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 return err;
2135
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002136 err = gfar_request_irq(priv);
2137 if (err)
2138 return err;
2139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 err = startup_gfar(dev);
Claudiu Manoil08511332014-02-24 12:13:45 +02002141 if (err)
Anton Vorontsovdb0e8e32007-10-17 23:57:46 +04002142 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08002144 device_set_wakeup_enable(&dev->dev, priv->wol_en);
2145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 return err;
2147}
2148
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002149static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002150{
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002151 struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
Kumar Gala6c31d552009-04-28 08:04:10 -07002152
2153 memset(fcb, 0, GMAC_FCB_LEN);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002154
Kumar Gala0bbaf062005-06-20 10:54:21 -05002155 return fcb;
2156}
2157
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002158static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002159 int fcb_length)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002160{
Kumar Gala0bbaf062005-06-20 10:54:21 -05002161 /* If we're here, it's a IP packet with a TCP or UDP
2162 * payload. We set it to checksum, using a pseudo-header
2163 * we provide
2164 */
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +00002165 u8 flags = TXFCB_DEFAULT;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002166
Jan Ceuleers0977f812012-06-05 03:42:12 +00002167 /* Tell the controller what the protocol is
2168 * And provide the already calculated phcs
2169 */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002170 if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
Andy Fleming7f7f5312005-11-11 12:38:59 -06002171 flags |= TXFCB_UDP;
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002172 fcb->phcs = (__force __be16)(udp_hdr(skb)->check);
Andy Fleming7f7f5312005-11-11 12:38:59 -06002173 } else
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002174 fcb->phcs = (__force __be16)(tcp_hdr(skb)->check);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002175
2176 /* l3os is the distance between the start of the
2177 * frame (skb->data) and the start of the IP hdr.
2178 * l4os is the distance between the start of the
Jan Ceuleers0977f812012-06-05 03:42:12 +00002179 * l3 hdr and the l4 hdr
2180 */
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002181 fcb->l3os = (u8)(skb_network_offset(skb) - fcb_length);
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -03002182 fcb->l4os = skb_network_header_len(skb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002183
Andy Fleming7f7f5312005-11-11 12:38:59 -06002184 fcb->flags = flags;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002185}
2186
Andy Fleming7f7f5312005-11-11 12:38:59 -06002187void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002188{
Andy Fleming7f7f5312005-11-11 12:38:59 -06002189 fcb->flags |= TXFCB_VLN;
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002190 fcb->vlctl = cpu_to_be16(skb_vlan_tag_get(skb));
Kumar Gala0bbaf062005-06-20 10:54:21 -05002191}
2192
Dai Haruki4669bc92008-12-17 16:51:04 -08002193static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002194 struct txbd8 *base, int ring_size)
Dai Haruki4669bc92008-12-17 16:51:04 -08002195{
2196 struct txbd8 *new_bd = bdp + stride;
2197
2198 return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
2199}
2200
2201static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002202 int ring_size)
Dai Haruki4669bc92008-12-17 16:51:04 -08002203{
2204 return skip_txbd(bdp, 1, base, ring_size);
2205}
2206
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002207/* eTSEC12: csum generation not supported for some fcb offsets */
2208static inline bool gfar_csum_errata_12(struct gfar_private *priv,
2209 unsigned long fcb_addr)
2210{
2211 return (gfar_has_errata(priv, GFAR_ERRATA_12) &&
2212 (fcb_addr % 0x20) > 0x18);
2213}
2214
2215/* eTSEC76: csum generation for frames larger than 2500 may
2216 * cause excess delays before start of transmission
2217 */
2218static inline bool gfar_csum_errata_76(struct gfar_private *priv,
2219 unsigned int len)
2220{
2221 return (gfar_has_errata(priv, GFAR_ERRATA_76) &&
2222 (len > 2500));
2223}
2224
Jan Ceuleers0977f812012-06-05 03:42:12 +00002225/* This is called by the kernel when a frame is ready for transmission.
2226 * It is pointed to by the dev->hard_start_xmit function pointer
2227 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2229{
2230 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002231 struct gfar_priv_tx_q *tx_queue = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002232 struct netdev_queue *txq;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002233 struct gfar __iomem *regs = NULL;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002234 struct txfcb *fcb = NULL;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002235 struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL;
Dai Haruki5a5efed2008-12-16 15:34:50 -08002236 u32 lstatus;
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002237 int i, rq = 0;
2238 int do_tstamp, do_csum, do_vlan;
Dai Haruki4669bc92008-12-17 16:51:04 -08002239 u32 bufaddr;
Andy Flemingfef61082006-04-20 16:44:29 -05002240 unsigned long flags;
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002241 unsigned int nr_frags, nr_txbds, bytes_sent, fcb_len = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002242
2243 rq = skb->queue_mapping;
2244 tx_queue = priv->tx_queue[rq];
2245 txq = netdev_get_tx_queue(dev, rq);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002246 base = tx_queue->tx_bd_base;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002247 regs = tx_queue->grp->regs;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002248
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002249 do_csum = (CHECKSUM_PARTIAL == skb->ip_summed);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002250 do_vlan = skb_vlan_tag_present(skb);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002251 do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
2252 priv->hwts_tx_en;
2253
2254 if (do_csum || do_vlan)
2255 fcb_len = GMAC_FCB_LEN;
2256
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002257 /* check if time stamp should be generated */
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002258 if (unlikely(do_tstamp))
2259 fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
Dai Haruki4669bc92008-12-17 16:51:04 -08002260
Li Yang5b28bea2009-03-27 15:54:30 -07002261 /* make space for additional header when fcb is needed */
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002262 if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) {
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002263 struct sk_buff *skb_new;
2264
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002265 skb_new = skb_realloc_headroom(skb, fcb_len);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002266 if (!skb_new) {
2267 dev->stats.tx_errors++;
Eric W. Biedermanc9974ad2014-03-11 14:20:26 -07002268 dev_kfree_skb_any(skb);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002269 return NETDEV_TX_OK;
2270 }
Manfred Rudigierdb83d132012-01-09 23:26:50 +00002271
Eric Dumazet313b0372012-07-05 11:45:13 +00002272 if (skb->sk)
2273 skb_set_owner_w(skb_new, skb->sk);
Eric W. Biedermanc9974ad2014-03-11 14:20:26 -07002274 dev_consume_skb_any(skb);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002275 skb = skb_new;
2276 }
2277
Dai Haruki4669bc92008-12-17 16:51:04 -08002278 /* total number of fragments in the SKB */
2279 nr_frags = skb_shinfo(skb)->nr_frags;
2280
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002281 /* calculate the required number of TxBDs for this skb */
2282 if (unlikely(do_tstamp))
2283 nr_txbds = nr_frags + 2;
2284 else
2285 nr_txbds = nr_frags + 1;
2286
Dai Haruki4669bc92008-12-17 16:51:04 -08002287 /* check if there is space to queue this packet */
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002288 if (nr_txbds > tx_queue->num_txbdfree) {
Dai Haruki4669bc92008-12-17 16:51:04 -08002289 /* no space, stop the queue */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002290 netif_tx_stop_queue(txq);
Dai Haruki4669bc92008-12-17 16:51:04 -08002291 dev->stats.tx_fifo_errors++;
Dai Haruki4669bc92008-12-17 16:51:04 -08002292 return NETDEV_TX_BUSY;
2293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 /* Update transmit stats */
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002296 bytes_sent = skb->len;
2297 tx_queue->stats.tx_bytes += bytes_sent;
2298 /* keep Tx bytes on wire for BQL accounting */
2299 GFAR_CB(skb)->bytes_sent = bytes_sent;
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00002300 tx_queue->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002302 txbdp = txbdp_start = tx_queue->cur_tx;
Claudiu Manoila7312d52015-03-13 10:36:28 +02002303 lstatus = be32_to_cpu(txbdp->lstatus);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002304
2305 /* Time stamp insertion requires one additional TxBD */
2306 if (unlikely(do_tstamp))
2307 txbdp_tstamp = txbdp = next_txbd(txbdp, base,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002308 tx_queue->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Dai Haruki4669bc92008-12-17 16:51:04 -08002310 if (nr_frags == 0) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002311 if (unlikely(do_tstamp)) {
2312 u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus);
2313
2314 lstatus_ts |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
2315 txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts);
2316 } else {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002317 lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002318 }
Dai Haruki4669bc92008-12-17 16:51:04 -08002319 } else {
2320 /* Place the fragment addresses and lengths into the TxBDs */
2321 for (i = 0; i < nr_frags; i++) {
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002322 unsigned int frag_len;
Dai Haruki4669bc92008-12-17 16:51:04 -08002323 /* Point at the next BD, wrapping as needed */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002324 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002326 frag_len = skb_shinfo(skb)->frags[i].size;
Dai Haruki4669bc92008-12-17 16:51:04 -08002327
Claudiu Manoila7312d52015-03-13 10:36:28 +02002328 lstatus = be32_to_cpu(txbdp->lstatus) | frag_len |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002329 BD_LFLAG(TXBD_READY);
Dai Haruki4669bc92008-12-17 16:51:04 -08002330
2331 /* Handle the last BD specially */
2332 if (i == nr_frags - 1)
2333 lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
2334
Claudiu Manoil369ec162013-02-14 05:00:02 +00002335 bufaddr = skb_frag_dma_map(priv->dev,
Ian Campbell2234a722011-08-29 23:18:29 +00002336 &skb_shinfo(skb)->frags[i],
2337 0,
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002338 frag_len,
Ian Campbell2234a722011-08-29 23:18:29 +00002339 DMA_TO_DEVICE);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002340 if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
2341 goto dma_map_err;
Dai Haruki4669bc92008-12-17 16:51:04 -08002342
2343 /* set the TxBD length and buffer pointer */
Claudiu Manoila7312d52015-03-13 10:36:28 +02002344 txbdp->bufPtr = cpu_to_be32(bufaddr);
2345 txbdp->lstatus = cpu_to_be32(lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002346 }
2347
Claudiu Manoila7312d52015-03-13 10:36:28 +02002348 lstatus = be32_to_cpu(txbdp_start->lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002351 /* Add TxPAL between FCB and frame if required */
2352 if (unlikely(do_tstamp)) {
2353 skb_push(skb, GMAC_TXPAL_LEN);
2354 memset(skb->data, 0, GMAC_TXPAL_LEN);
2355 }
2356
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002357 /* Add TxFCB if required */
2358 if (fcb_len) {
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002359 fcb = gfar_add_fcb(skb);
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002360 lstatus |= BD_LFLAG(TXBD_TOE);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002361 }
2362
2363 /* Set up checksumming */
2364 if (do_csum) {
2365 gfar_tx_checksum(skb, fcb, fcb_len);
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002366
2367 if (unlikely(gfar_csum_errata_12(priv, (unsigned long)fcb)) ||
2368 unlikely(gfar_csum_errata_76(priv, skb->len))) {
Alex Dubov4363c2fdd2011-03-16 17:57:13 +00002369 __skb_pull(skb, GMAC_FCB_LEN);
2370 skb_checksum_help(skb);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002371 if (do_vlan || do_tstamp) {
2372 /* put back a new fcb for vlan/tstamp TOE */
2373 fcb = gfar_add_fcb(skb);
2374 } else {
2375 /* Tx TOE not used */
2376 lstatus &= ~(BD_LFLAG(TXBD_TOE));
2377 fcb = NULL;
2378 }
Alex Dubov4363c2fdd2011-03-16 17:57:13 +00002379 }
Kumar Gala0bbaf062005-06-20 10:54:21 -05002380 }
2381
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002382 if (do_vlan)
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002383 gfar_tx_vlan(skb, fcb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002384
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002385 /* Setup tx hardware time stamping if requested */
2386 if (unlikely(do_tstamp)) {
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002387 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002388 fcb->ptp = 1;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002389 }
2390
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002391 bufaddr = dma_map_single(priv->dev, skb->data, skb_headlen(skb),
2392 DMA_TO_DEVICE);
2393 if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
2394 goto dma_map_err;
2395
Claudiu Manoila7312d52015-03-13 10:36:28 +02002396 txbdp_start->bufPtr = cpu_to_be32(bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Jan Ceuleers0977f812012-06-05 03:42:12 +00002398 /* If time stamping is requested one additional TxBD must be set up. The
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002399 * first TxBD points to the FCB and must have a data length of
2400 * GMAC_FCB_LEN. The second TxBD points to the actual frame data with
2401 * the full frame length.
2402 */
2403 if (unlikely(do_tstamp)) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002404 u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus);
2405
2406 bufaddr = be32_to_cpu(txbdp_start->bufPtr);
2407 bufaddr += fcb_len;
2408 lstatus_ts |= BD_LFLAG(TXBD_READY) |
2409 (skb_headlen(skb) - fcb_len);
2410
2411 txbdp_tstamp->bufPtr = cpu_to_be32(bufaddr);
2412 txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002413 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
2414 } else {
2415 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
2416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002418 netdev_tx_sent_queue(txq, bytes_sent);
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002419
Jan Ceuleers0977f812012-06-05 03:42:12 +00002420 /* We can work in parallel with gfar_clean_tx_ring(), except
Anton Vorontsova3bc1f12009-11-10 14:11:10 +00002421 * when modifying num_txbdfree. Note that we didn't grab the lock
2422 * when we were reading the num_txbdfree and checking for available
2423 * space, that's because outside of this function it can only grow,
2424 * and once we've got needed space, it cannot suddenly disappear.
2425 *
2426 * The lock also protects us from gfar_error(), which can modify
2427 * regs->tstat and thus retrigger the transfers, which is why we
2428 * also must grab the lock before setting ready bit for the first
2429 * to be transmitted BD.
2430 */
2431 spin_lock_irqsave(&tx_queue->txlock, flags);
2432
Claudiu Manoild55398b2014-10-07 10:44:35 +03002433 gfar_wmb();
Andy Fleming7f7f5312005-11-11 12:38:59 -06002434
Claudiu Manoila7312d52015-03-13 10:36:28 +02002435 txbdp_start->lstatus = cpu_to_be32(lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002436
Claudiu Manoild55398b2014-10-07 10:44:35 +03002437 gfar_wmb(); /* force lstatus write before tx_skbuff */
Anton Vorontsov0eddba52010-03-03 08:18:58 +00002438
2439 tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb;
2440
Dai Haruki4669bc92008-12-17 16:51:04 -08002441 /* Update the current skb pointer to the next entry we will use
Jan Ceuleers0977f812012-06-05 03:42:12 +00002442 * (wrapping if necessary)
2443 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002444 tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) &
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002445 TX_RING_MOD_MASK(tx_queue->tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002446
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002447 tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002448
2449 /* reduce TxBD free count */
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002450 tx_queue->num_txbdfree -= (nr_txbds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 /* If the next BD still needs to be cleaned up, then the bds
Jan Ceuleers0977f812012-06-05 03:42:12 +00002453 * are full. We need to tell the kernel to stop sending us stuff.
2454 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002455 if (!tx_queue->num_txbdfree) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002456 netif_tx_stop_queue(txq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002458 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 }
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 /* Tell the DMA to go go go */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002462 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
2464 /* Unlock priv */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002465 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002467 return NETDEV_TX_OK;
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002468
2469dma_map_err:
2470 txbdp = next_txbd(txbdp_start, base, tx_queue->tx_ring_size);
2471 if (do_tstamp)
2472 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
2473 for (i = 0; i < nr_frags; i++) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002474 lstatus = be32_to_cpu(txbdp->lstatus);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002475 if (!(lstatus & BD_LFLAG(TXBD_READY)))
2476 break;
2477
Claudiu Manoila7312d52015-03-13 10:36:28 +02002478 lstatus &= ~BD_LFLAG(TXBD_READY);
2479 txbdp->lstatus = cpu_to_be32(lstatus);
2480 bufaddr = be32_to_cpu(txbdp->bufPtr);
2481 dma_unmap_page(priv->dev, bufaddr, be16_to_cpu(txbdp->length),
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002482 DMA_TO_DEVICE);
2483 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
2484 }
2485 gfar_wmb();
2486 dev_kfree_skb_any(skb);
2487 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
2490/* Stops the kernel queue, and halts the controller */
2491static int gfar_close(struct net_device *dev)
2492{
2493 struct gfar_private *priv = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002494
Sebastian Siewiorab939902008-08-19 21:12:45 +02002495 cancel_work_sync(&priv->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 stop_gfar(dev);
2497
Andy Flemingbb40dcb2005-09-23 22:54:21 -04002498 /* Disconnect from the PHY */
2499 phy_disconnect(priv->phydev);
2500 priv->phydev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002502 gfar_free_irq(priv);
2503
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 return 0;
2505}
2506
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507/* Changes the mac address if the controller is not running. */
Andy Flemingf162b9d2008-05-02 13:00:30 -05002508static int gfar_set_mac_address(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509{
Andy Fleming7f7f5312005-11-11 12:38:59 -06002510 gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 return 0;
2513}
2514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515static int gfar_change_mtu(struct net_device *dev, int new_mtu)
2516{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002518 int frame_size = new_mtu + ETH_HLEN;
2519
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
Joe Perches59deab22011-06-14 08:57:47 +00002521 netif_err(priv, drv, dev, "Invalid MTU setting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 return -EINVAL;
2523 }
2524
Claudiu Manoil08511332014-02-24 12:13:45 +02002525 while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
2526 cpu_relax();
2527
Claudiu Manoil88302642014-02-24 12:13:43 +02002528 if (dev->flags & IFF_UP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 stop_gfar(dev);
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 dev->mtu = new_mtu;
2532
Claudiu Manoil88302642014-02-24 12:13:43 +02002533 if (dev->flags & IFF_UP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 startup_gfar(dev);
2535
Claudiu Manoil08511332014-02-24 12:13:45 +02002536 clear_bit_unlock(GFAR_RESETTING, &priv->state);
2537
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 return 0;
2539}
2540
Claudiu Manoil08511332014-02-24 12:13:45 +02002541void reset_gfar(struct net_device *ndev)
2542{
2543 struct gfar_private *priv = netdev_priv(ndev);
2544
2545 while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
2546 cpu_relax();
2547
2548 stop_gfar(ndev);
2549 startup_gfar(ndev);
2550
2551 clear_bit_unlock(GFAR_RESETTING, &priv->state);
2552}
2553
Sebastian Siewiorab939902008-08-19 21:12:45 +02002554/* gfar_reset_task gets scheduled when a packet has not been
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 * transmitted after a set amount of time.
2556 * For now, assume that clearing out all the structures, and
Sebastian Siewiorab939902008-08-19 21:12:45 +02002557 * starting over will fix the problem.
2558 */
2559static void gfar_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Sebastian Siewiorab939902008-08-19 21:12:45 +02002561 struct gfar_private *priv = container_of(work, struct gfar_private,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002562 reset_task);
Claudiu Manoil08511332014-02-24 12:13:45 +02002563 reset_gfar(priv->ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
Sebastian Siewiorab939902008-08-19 21:12:45 +02002566static void gfar_timeout(struct net_device *dev)
2567{
2568 struct gfar_private *priv = netdev_priv(dev);
2569
2570 dev->stats.tx_errors++;
2571 schedule_work(&priv->reset_task);
2572}
2573
Eran Libertyacbc0f02010-07-07 15:54:54 -07002574static void gfar_align_skb(struct sk_buff *skb)
2575{
2576 /* We need the data buffer to be aligned properly. We will reserve
2577 * as many bytes as needed to align the data properly
2578 */
2579 skb_reserve(skb, RXBUF_ALIGNMENT -
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002580 (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1)));
Eran Libertyacbc0f02010-07-07 15:54:54 -07002581}
2582
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583/* Interrupt Handler for Transmit complete */
Claudiu Manoilc233cf402013-03-19 07:40:02 +00002584static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002586 struct net_device *dev = tx_queue->dev;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002587 struct netdev_queue *txq;
Dai Harukid080cd62008-04-09 19:37:51 -05002588 struct gfar_private *priv = netdev_priv(dev);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002589 struct txbd8 *bdp, *next = NULL;
Dai Haruki4669bc92008-12-17 16:51:04 -08002590 struct txbd8 *lbdp = NULL;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002591 struct txbd8 *base = tx_queue->tx_bd_base;
Dai Haruki4669bc92008-12-17 16:51:04 -08002592 struct sk_buff *skb;
2593 int skb_dirtytx;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002594 int tx_ring_size = tx_queue->tx_ring_size;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002595 int frags = 0, nr_txbds = 0;
Dai Haruki4669bc92008-12-17 16:51:04 -08002596 int i;
Dai Harukid080cd62008-04-09 19:37:51 -05002597 int howmany = 0;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002598 int tqi = tx_queue->qindex;
2599 unsigned int bytes_sent = 0;
Dai Haruki4669bc92008-12-17 16:51:04 -08002600 u32 lstatus;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002601 size_t buflen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002603 txq = netdev_get_tx_queue(dev, tqi);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002604 bdp = tx_queue->dirty_tx;
2605 skb_dirtytx = tx_queue->skb_dirtytx;
Dai Haruki4669bc92008-12-17 16:51:04 -08002606
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002607 while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) {
Anton Vorontsova3bc1f12009-11-10 14:11:10 +00002608 unsigned long flags;
2609
Dai Haruki4669bc92008-12-17 16:51:04 -08002610 frags = skb_shinfo(skb)->nr_frags;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002611
Jan Ceuleers0977f812012-06-05 03:42:12 +00002612 /* When time stamping, one additional TxBD must be freed.
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002613 * Also, we need to dma_unmap_single() the TxPAL.
2614 */
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002615 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002616 nr_txbds = frags + 2;
2617 else
2618 nr_txbds = frags + 1;
2619
2620 lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002621
Claudiu Manoila7312d52015-03-13 10:36:28 +02002622 lstatus = be32_to_cpu(lbdp->lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002623
2624 /* Only clean completed frames */
2625 if ((lstatus & BD_LFLAG(TXBD_READY)) &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002626 (lstatus & BD_LENGTH_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 break;
2628
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002629 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002630 next = next_txbd(bdp, base, tx_ring_size);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002631 buflen = be16_to_cpu(next->length) +
2632 GMAC_FCB_LEN + GMAC_TXPAL_LEN;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002633 } else
Claudiu Manoila7312d52015-03-13 10:36:28 +02002634 buflen = be16_to_cpu(bdp->length);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002635
Claudiu Manoila7312d52015-03-13 10:36:28 +02002636 dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr),
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002637 buflen, DMA_TO_DEVICE);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002638
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002639 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002640 struct skb_shared_hwtstamps shhwtstamps;
2641 u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002642
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002643 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
2644 shhwtstamps.hwtstamp = ns_to_ktime(*ns);
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002645 skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002646 skb_tstamp_tx(skb, &shhwtstamps);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002647 gfar_clear_txbd_status(bdp);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002648 bdp = next;
2649 }
Dai Haruki4669bc92008-12-17 16:51:04 -08002650
Claudiu Manoila7312d52015-03-13 10:36:28 +02002651 gfar_clear_txbd_status(bdp);
Dai Haruki4669bc92008-12-17 16:51:04 -08002652 bdp = next_txbd(bdp, base, tx_ring_size);
2653
2654 for (i = 0; i < frags; i++) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002655 dma_unmap_page(priv->dev, be32_to_cpu(bdp->bufPtr),
2656 be16_to_cpu(bdp->length),
2657 DMA_TO_DEVICE);
2658 gfar_clear_txbd_status(bdp);
Dai Haruki4669bc92008-12-17 16:51:04 -08002659 bdp = next_txbd(bdp, base, tx_ring_size);
2660 }
2661
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002662 bytes_sent += GFAR_CB(skb)->bytes_sent;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002663
Eric Dumazetacb600d2012-10-05 06:23:55 +00002664 dev_kfree_skb_any(skb);
Andy Fleming0fd56bb2009-02-04 16:43:16 -08002665
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002666 tx_queue->tx_skbuff[skb_dirtytx] = NULL;
Dai Haruki4669bc92008-12-17 16:51:04 -08002667
2668 skb_dirtytx = (skb_dirtytx + 1) &
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002669 TX_RING_MOD_MASK(tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002670
Dai Harukid080cd62008-04-09 19:37:51 -05002671 howmany++;
Anton Vorontsova3bc1f12009-11-10 14:11:10 +00002672 spin_lock_irqsave(&tx_queue->txlock, flags);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002673 tx_queue->num_txbdfree += nr_txbds;
Anton Vorontsova3bc1f12009-11-10 14:11:10 +00002674 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Dai Haruki4669bc92008-12-17 16:51:04 -08002675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Dai Haruki4669bc92008-12-17 16:51:04 -08002677 /* If we freed a buffer, we can restart transmission, if necessary */
Claudiu Manoil08511332014-02-24 12:13:45 +02002678 if (tx_queue->num_txbdfree &&
2679 netif_tx_queue_stopped(txq) &&
2680 !(test_bit(GFAR_DOWN, &priv->state)))
2681 netif_wake_subqueue(priv->ndev, tqi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Dai Haruki4669bc92008-12-17 16:51:04 -08002683 /* Update dirty indicators */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002684 tx_queue->skb_dirtytx = skb_dirtytx;
2685 tx_queue->dirty_tx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002687 netdev_tx_completed_queue(txq, howmany, bytes_sent);
Dai Harukid080cd62008-04-09 19:37:51 -05002688}
2689
Jan Ceuleers2281a0f2012-06-05 03:42:11 +00002690static struct sk_buff *gfar_alloc_skb(struct net_device *dev)
Eran Libertyacbc0f02010-07-07 15:54:54 -07002691{
2692 struct gfar_private *priv = netdev_priv(dev);
Eric Dumazetacb600d2012-10-05 06:23:55 +00002693 struct sk_buff *skb;
Eran Libertyacbc0f02010-07-07 15:54:54 -07002694
2695 skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
2696 if (!skb)
2697 return NULL;
2698
2699 gfar_align_skb(skb);
2700
2701 return skb;
2702}
Andy Fleming815b97c2008-04-22 17:18:29 -05002703
Kevin Hao91c53f762014-12-24 14:05:44 +08002704static struct sk_buff *gfar_new_skb(struct net_device *dev, dma_addr_t *bufaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002706 struct gfar_private *priv = netdev_priv(dev);
2707 struct sk_buff *skb;
2708 dma_addr_t addr;
2709
2710 skb = gfar_alloc_skb(dev);
2711 if (!skb)
2712 return NULL;
2713
2714 addr = dma_map_single(priv->dev, skb->data,
2715 priv->rx_buffer_size, DMA_FROM_DEVICE);
2716 if (unlikely(dma_mapping_error(priv->dev, addr))) {
2717 dev_kfree_skb_any(skb);
2718 return NULL;
2719 }
2720
2721 *bufaddr = addr;
2722 return skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723}
2724
Li Yang298e1a92007-10-16 14:18:13 +08002725static inline void count_errors(unsigned short status, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726{
Li Yang298e1a92007-10-16 14:18:13 +08002727 struct gfar_private *priv = netdev_priv(dev);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002728 struct net_device_stats *stats = &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 struct gfar_extra_stats *estats = &priv->extra_stats;
2730
Jan Ceuleers0977f812012-06-05 03:42:12 +00002731 /* If the packet was truncated, none of the other errors matter */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if (status & RXBD_TRUNCATED) {
2733 stats->rx_length_errors++;
2734
Paul Gortmaker212079d2013-02-12 15:38:19 -05002735 atomic64_inc(&estats->rx_trunc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
2737 return;
2738 }
2739 /* Count the errors, if there were any */
2740 if (status & (RXBD_LARGE | RXBD_SHORT)) {
2741 stats->rx_length_errors++;
2742
2743 if (status & RXBD_LARGE)
Paul Gortmaker212079d2013-02-12 15:38:19 -05002744 atomic64_inc(&estats->rx_large);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 else
Paul Gortmaker212079d2013-02-12 15:38:19 -05002746 atomic64_inc(&estats->rx_short);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 }
2748 if (status & RXBD_NONOCTET) {
2749 stats->rx_frame_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05002750 atomic64_inc(&estats->rx_nonoctet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 }
2752 if (status & RXBD_CRCERR) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05002753 atomic64_inc(&estats->rx_crcerr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 stats->rx_crc_errors++;
2755 }
2756 if (status & RXBD_OVERRUN) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05002757 atomic64_inc(&estats->rx_overrun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 stats->rx_crc_errors++;
2759 }
2760}
2761
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002762irqreturn_t gfar_receive(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763{
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002764 struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
2765 unsigned long flags;
2766 u32 imask;
2767
2768 if (likely(napi_schedule_prep(&grp->napi_rx))) {
2769 spin_lock_irqsave(&grp->grplock, flags);
2770 imask = gfar_read(&grp->regs->imask);
2771 imask &= IMASK_RX_DISABLED;
2772 gfar_write(&grp->regs->imask, imask);
2773 spin_unlock_irqrestore(&grp->grplock, flags);
2774 __napi_schedule(&grp->napi_rx);
2775 } else {
2776 /* Clear IEVENT, so interrupts aren't called again
2777 * because of the packets that have already arrived.
2778 */
2779 gfar_write(&grp->regs->ievent, IEVENT_RX_MASK);
2780 }
2781
2782 return IRQ_HANDLED;
2783}
2784
2785/* Interrupt Handler for Transmit complete */
2786static irqreturn_t gfar_transmit(int irq, void *grp_id)
2787{
2788 struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
2789 unsigned long flags;
2790 u32 imask;
2791
2792 if (likely(napi_schedule_prep(&grp->napi_tx))) {
2793 spin_lock_irqsave(&grp->grplock, flags);
2794 imask = gfar_read(&grp->regs->imask);
2795 imask &= IMASK_TX_DISABLED;
2796 gfar_write(&grp->regs->imask, imask);
2797 spin_unlock_irqrestore(&grp->grplock, flags);
2798 __napi_schedule(&grp->napi_tx);
2799 } else {
2800 /* Clear IEVENT, so interrupts aren't called again
2801 * because of the packets that have already arrived.
2802 */
2803 gfar_write(&grp->regs->ievent, IEVENT_TX_MASK);
2804 }
2805
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 return IRQ_HANDLED;
2807}
2808
Kumar Gala0bbaf062005-06-20 10:54:21 -05002809static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
2810{
2811 /* If valid headers were found, and valid sums
2812 * were verified, then we tell the kernel that no
Jan Ceuleers0977f812012-06-05 03:42:12 +00002813 * checksumming is necessary. Otherwise, it is [FIXME]
2814 */
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002815 if ((be16_to_cpu(fcb->flags) & RXFCB_CSUM_MASK) ==
2816 (RXFCB_CIP | RXFCB_CTU))
Kumar Gala0bbaf062005-06-20 10:54:21 -05002817 skb->ip_summed = CHECKSUM_UNNECESSARY;
2818 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -07002819 skb_checksum_none_assert(skb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002820}
2821
Jan Ceuleers0977f812012-06-05 03:42:12 +00002822/* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */
Claudiu Manoil61db26c2013-02-14 05:00:05 +00002823static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
2824 int amount_pull, struct napi_struct *napi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825{
2826 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002827 struct rxfcb *fcb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
Dai Haruki2c2db482008-12-16 15:31:15 -08002829 /* fcb is at the beginning if exists */
2830 fcb = (struct rxfcb *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
Jan Ceuleers0977f812012-06-05 03:42:12 +00002832 /* Remove the FCB from the skb
2833 * Remove the padded bytes, if there are any
2834 */
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002835 if (amount_pull) {
2836 skb_record_rx_queue(skb, fcb->rq);
Dai Haruki2c2db482008-12-16 15:31:15 -08002837 skb_pull(skb, amount_pull);
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002838 }
Kumar Gala0bbaf062005-06-20 10:54:21 -05002839
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00002840 /* Get receive timestamp from the skb */
2841 if (priv->hwts_rx_en) {
2842 struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
2843 u64 *ns = (u64 *) skb->data;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002844
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00002845 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
2846 shhwtstamps->hwtstamp = ns_to_ktime(*ns);
2847 }
2848
2849 if (priv->padding)
2850 skb_pull(skb, priv->padding);
2851
Michał Mirosław8b3afe92011-04-15 04:50:50 +00002852 if (dev->features & NETIF_F_RXCSUM)
Dai Haruki2c2db482008-12-16 15:31:15 -08002853 gfar_rx_checksum(skb, fcb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002854
Dai Haruki2c2db482008-12-16 15:31:15 -08002855 /* Tell the skb what kind of packet this is */
2856 skb->protocol = eth_type_trans(skb, dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002857
Patrick McHardyf6469682013-04-19 02:04:27 +00002858 /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here.
David S. Miller823dcd22011-08-20 10:39:12 -07002859 * Even if vlan rx accel is disabled, on some chips
2860 * RXFCB_VLN is pseudo randomly set.
2861 */
Patrick McHardyf6469682013-04-19 02:04:27 +00002862 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX &&
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002863 be16_to_cpu(fcb->flags) & RXFCB_VLN)
2864 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2865 be16_to_cpu(fcb->vlctl));
Jiri Pirko87c288c2011-07-20 04:54:19 +00002866
Dai Haruki2c2db482008-12-16 15:31:15 -08002867 /* Send the packet up the stack */
Claudiu Manoil953d2762013-03-21 03:12:15 +00002868 napi_gro_receive(napi, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870}
2871
2872/* gfar_clean_rx_ring() -- Processes each frame in the rx ring
Jan Ceuleers2281a0f2012-06-05 03:42:11 +00002873 * until the budget/quota has been reached. Returns the number
2874 * of frames handled
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002876int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877{
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002878 struct net_device *dev = rx_queue->dev;
Andy Fleming31de1982008-12-16 15:33:40 -08002879 struct rxbd8 *bdp, *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 struct sk_buff *skb;
Dai Haruki2c2db482008-12-16 15:31:15 -08002881 int pkt_len;
2882 int amount_pull;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 int howmany = 0;
2884 struct gfar_private *priv = netdev_priv(dev);
2885
2886 /* Get the first full descriptor */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002887 bdp = rx_queue->cur_rx;
2888 base = rx_queue->rx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
Claudiu Manoilba779712013-02-14 05:00:07 +00002890 amount_pull = priv->uses_rxfcb ? GMAC_FCB_LEN : 0;
Dai Haruki2c2db482008-12-16 15:31:15 -08002891
Claudiu Manoila7312d52015-03-13 10:36:28 +02002892 while (!(be16_to_cpu(bdp->status) & RXBD_EMPTY) && rx_work_limit--) {
Andy Fleming815b97c2008-04-22 17:18:29 -05002893 struct sk_buff *newskb;
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002894 dma_addr_t bufaddr;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002895
Scott Wood3b6330c2007-05-16 15:06:59 -05002896 rmb();
Andy Fleming815b97c2008-04-22 17:18:29 -05002897
2898 /* Add another skb for the future */
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002899 newskb = gfar_new_skb(dev, &bufaddr);
Andy Fleming815b97c2008-04-22 17:18:29 -05002900
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002901 skb = rx_queue->rx_skbuff[rx_queue->skb_currx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Claudiu Manoila7312d52015-03-13 10:36:28 +02002903 dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr),
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002904 priv->rx_buffer_size, DMA_FROM_DEVICE);
Andy Fleming81183052008-11-12 10:07:11 -06002905
Claudiu Manoila7312d52015-03-13 10:36:28 +02002906 if (unlikely(!(be16_to_cpu(bdp->status) & RXBD_ERR) &&
2907 be16_to_cpu(bdp->length) > priv->rx_buffer_size))
2908 bdp->status = cpu_to_be16(RXBD_LARGE);
Anton Vorontsov63b88b92010-06-11 10:51:03 +00002909
Andy Fleming815b97c2008-04-22 17:18:29 -05002910 /* We drop the frame if we failed to allocate a new buffer */
Claudiu Manoila7312d52015-03-13 10:36:28 +02002911 if (unlikely(!newskb ||
2912 !(be16_to_cpu(bdp->status) & RXBD_LAST) ||
2913 be16_to_cpu(bdp->status) & RXBD_ERR)) {
2914 count_errors(be16_to_cpu(bdp->status), dev);
Andy Fleming815b97c2008-04-22 17:18:29 -05002915
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002916 if (unlikely(!newskb)) {
Andy Fleming815b97c2008-04-22 17:18:29 -05002917 newskb = skb;
Claudiu Manoila7312d52015-03-13 10:36:28 +02002918 bufaddr = be32_to_cpu(bdp->bufPtr);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002919 } else if (skb)
Eric Dumazetacb600d2012-10-05 06:23:55 +00002920 dev_kfree_skb(skb);
Andy Fleming815b97c2008-04-22 17:18:29 -05002921 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 /* Increment the number of packets */
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002923 rx_queue->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 howmany++;
2925
Dai Haruki2c2db482008-12-16 15:31:15 -08002926 if (likely(skb)) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002927 pkt_len = be16_to_cpu(bdp->length) -
2928 ETH_FCS_LEN;
Dai Haruki2c2db482008-12-16 15:31:15 -08002929 /* Remove the FCS from the packet length */
2930 skb_put(skb, pkt_len);
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002931 rx_queue->stats.rx_bytes += pkt_len;
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002932 skb_record_rx_queue(skb, rx_queue->qindex);
Wu Jiajun-B06378cd754a52012-04-19 22:54:35 +00002933 gfar_process_frame(dev, skb, amount_pull,
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002934 &rx_queue->grp->napi_rx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
Dai Haruki2c2db482008-12-16 15:31:15 -08002936 } else {
Joe Perches59deab22011-06-14 08:57:47 +00002937 netif_warn(priv, rx_err, dev, "Missing skb!\n");
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002938 rx_queue->stats.rx_dropped++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05002939 atomic64_inc(&priv->extra_stats.rx_skbmissing);
Dai Haruki2c2db482008-12-16 15:31:15 -08002940 }
2941
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 }
2943
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002944 rx_queue->rx_skbuff[rx_queue->skb_currx] = newskb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
Andy Fleming815b97c2008-04-22 17:18:29 -05002946 /* Setup the new bdp */
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002947 gfar_init_rxbdp(rx_queue, bdp, bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Matei Pavaluca45b679c92014-10-27 10:42:44 +02002949 /* Update Last Free RxBD pointer for LFC */
2950 if (unlikely(rx_queue->rfbptr && priv->tx_actual_en))
2951 gfar_write(rx_queue->rfbptr, (u32)bdp);
2952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 /* Update to the next pointer */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002954 bdp = next_bd(bdp, base, rx_queue->rx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
2956 /* update to point at the next skb */
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002957 rx_queue->skb_currx = (rx_queue->skb_currx + 1) &
2958 RX_RING_MOD_MASK(rx_queue->rx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 }
2960
2961 /* Update the current rxbd pointer to be the next one */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002962 rx_queue->cur_rx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 return howmany;
2965}
2966
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002967static int gfar_poll_rx_sq(struct napi_struct *napi, int budget)
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002968{
2969 struct gfar_priv_grp *gfargrp =
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002970 container_of(napi, struct gfar_priv_grp, napi_rx);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002971 struct gfar __iomem *regs = gfargrp->regs;
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02002972 struct gfar_priv_rx_q *rx_queue = gfargrp->rx_queue;
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002973 int work_done = 0;
2974
2975 /* Clear IEVENT, so interrupts aren't called again
2976 * because of the packets that have already arrived
2977 */
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002978 gfar_write(&regs->ievent, IEVENT_RX_MASK);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002979
2980 work_done = gfar_clean_rx_ring(rx_queue, budget);
2981
2982 if (work_done < budget) {
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002983 u32 imask;
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002984 napi_complete(napi);
2985 /* Clear the halt bit in RSTAT */
2986 gfar_write(&regs->rstat, gfargrp->rstat);
2987
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002988 spin_lock_irq(&gfargrp->grplock);
2989 imask = gfar_read(&regs->imask);
2990 imask |= IMASK_RX_DEFAULT;
2991 gfar_write(&regs->imask, imask);
2992 spin_unlock_irq(&gfargrp->grplock);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002993 }
2994
2995 return work_done;
2996}
2997
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002998static int gfar_poll_tx_sq(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999{
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003000 struct gfar_priv_grp *gfargrp =
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003001 container_of(napi, struct gfar_priv_grp, napi_tx);
3002 struct gfar __iomem *regs = gfargrp->regs;
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02003003 struct gfar_priv_tx_q *tx_queue = gfargrp->tx_queue;
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003004 u32 imask;
3005
3006 /* Clear IEVENT, so interrupts aren't called again
3007 * because of the packets that have already arrived
3008 */
3009 gfar_write(&regs->ievent, IEVENT_TX_MASK);
3010
3011 /* run Tx cleanup to completion */
3012 if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx])
3013 gfar_clean_tx_ring(tx_queue);
3014
3015 napi_complete(napi);
3016
3017 spin_lock_irq(&gfargrp->grplock);
3018 imask = gfar_read(&regs->imask);
3019 imask |= IMASK_TX_DEFAULT;
3020 gfar_write(&regs->imask, imask);
3021 spin_unlock_irq(&gfargrp->grplock);
3022
3023 return 0;
3024}
3025
3026static int gfar_poll_rx(struct napi_struct *napi, int budget)
3027{
3028 struct gfar_priv_grp *gfargrp =
3029 container_of(napi, struct gfar_priv_grp, napi_rx);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003030 struct gfar_private *priv = gfargrp->priv;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003031 struct gfar __iomem *regs = gfargrp->regs;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003032 struct gfar_priv_rx_q *rx_queue = NULL;
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003033 int work_done = 0, work_done_per_q = 0;
Claudiu Manoil39c0a0d2013-03-21 03:12:13 +00003034 int i, budget_per_q = 0;
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003035 unsigned long rstat_rxf;
3036 int num_act_queues;
Dai Harukid080cd62008-04-09 19:37:51 -05003037
Dai Haruki8c7396a2008-12-17 16:52:00 -08003038 /* Clear IEVENT, so interrupts aren't called again
Jan Ceuleers0977f812012-06-05 03:42:12 +00003039 * because of the packets that have already arrived
3040 */
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003041 gfar_write(&regs->ievent, IEVENT_RX_MASK);
Dai Haruki8c7396a2008-12-17 16:52:00 -08003042
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003043 rstat_rxf = gfar_read(&regs->rstat) & RSTAT_RXF_MASK;
3044
3045 num_act_queues = bitmap_weight(&rstat_rxf, MAX_RX_QS);
3046 if (num_act_queues)
3047 budget_per_q = budget/num_act_queues;
3048
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003049 for_each_set_bit(i, &gfargrp->rx_bit_map, priv->num_rx_queues) {
3050 /* skip queue if not active */
3051 if (!(rstat_rxf & (RSTAT_CLEAR_RXF0 >> i)))
3052 continue;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003053
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003054 rx_queue = priv->rx_queue[i];
3055 work_done_per_q =
3056 gfar_clean_rx_ring(rx_queue, budget_per_q);
3057 work_done += work_done_per_q;
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003058
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003059 /* finished processing this queue */
3060 if (work_done_per_q < budget_per_q) {
3061 /* clear active queue hw indication */
3062 gfar_write(&regs->rstat,
3063 RSTAT_CLEAR_RXF0 >> i);
3064 num_act_queues--;
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003065
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003066 if (!num_act_queues)
3067 break;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003068 }
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003069 }
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003070
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003071 if (!num_act_queues) {
3072 u32 imask;
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003073 napi_complete(napi);
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003074
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003075 /* Clear the halt bit in RSTAT */
3076 gfar_write(&regs->rstat, gfargrp->rstat);
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003077
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003078 spin_lock_irq(&gfargrp->grplock);
3079 imask = gfar_read(&regs->imask);
3080 imask |= IMASK_RX_DEFAULT;
3081 gfar_write(&regs->imask, imask);
3082 spin_unlock_irq(&gfargrp->grplock);
Dai Harukid080cd62008-04-09 19:37:51 -05003083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003085 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003088static int gfar_poll_tx(struct napi_struct *napi, int budget)
3089{
3090 struct gfar_priv_grp *gfargrp =
3091 container_of(napi, struct gfar_priv_grp, napi_tx);
3092 struct gfar_private *priv = gfargrp->priv;
3093 struct gfar __iomem *regs = gfargrp->regs;
3094 struct gfar_priv_tx_q *tx_queue = NULL;
3095 int has_tx_work = 0;
3096 int i;
3097
3098 /* Clear IEVENT, so interrupts aren't called again
3099 * because of the packets that have already arrived
3100 */
3101 gfar_write(&regs->ievent, IEVENT_TX_MASK);
3102
3103 for_each_set_bit(i, &gfargrp->tx_bit_map, priv->num_tx_queues) {
3104 tx_queue = priv->tx_queue[i];
3105 /* run Tx cleanup to completion */
3106 if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx]) {
3107 gfar_clean_tx_ring(tx_queue);
3108 has_tx_work = 1;
3109 }
3110 }
3111
3112 if (!has_tx_work) {
3113 u32 imask;
3114 napi_complete(napi);
3115
3116 spin_lock_irq(&gfargrp->grplock);
3117 imask = gfar_read(&regs->imask);
3118 imask |= IMASK_TX_DEFAULT;
3119 gfar_write(&regs->imask, imask);
3120 spin_unlock_irq(&gfargrp->grplock);
3121 }
3122
3123 return 0;
3124}
3125
3126
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003127#ifdef CONFIG_NET_POLL_CONTROLLER
Jan Ceuleers0977f812012-06-05 03:42:12 +00003128/* Polling 'interrupt' - used by things like netconsole to send skbs
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003129 * without having to re-enable interrupts. It's not called while
3130 * the interrupt routine is executing.
3131 */
3132static void gfar_netpoll(struct net_device *dev)
3133{
3134 struct gfar_private *priv = netdev_priv(dev);
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +00003135 int i;
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003136
3137 /* If the device has multiple interrupts, run tx/rx */
Andy Flemingb31a1d82008-12-16 15:29:15 -08003138 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003139 for (i = 0; i < priv->num_grps; i++) {
Paul Gortmaker62ed8392013-02-24 05:38:31 +00003140 struct gfar_priv_grp *grp = &priv->gfargrp[i];
3141
3142 disable_irq(gfar_irq(grp, TX)->irq);
3143 disable_irq(gfar_irq(grp, RX)->irq);
3144 disable_irq(gfar_irq(grp, ER)->irq);
3145 gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
3146 enable_irq(gfar_irq(grp, ER)->irq);
3147 enable_irq(gfar_irq(grp, RX)->irq);
3148 enable_irq(gfar_irq(grp, TX)->irq);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003149 }
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003150 } else {
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003151 for (i = 0; i < priv->num_grps; i++) {
Paul Gortmaker62ed8392013-02-24 05:38:31 +00003152 struct gfar_priv_grp *grp = &priv->gfargrp[i];
3153
3154 disable_irq(gfar_irq(grp, TX)->irq);
3155 gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
3156 enable_irq(gfar_irq(grp, TX)->irq);
Anton Vorontsov43de0042009-12-09 02:52:19 -08003157 }
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003158 }
3159}
3160#endif
3161
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162/* The interrupt handler for devices with one interrupt */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003163static irqreturn_t gfar_interrupt(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164{
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003165 struct gfar_priv_grp *gfargrp = grp_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167 /* Save ievent for future reference */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003168 u32 events = gfar_read(&gfargrp->regs->ievent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 /* Check for reception */
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003171 if (events & IEVENT_RX_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003172 gfar_receive(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
3174 /* Check for transmit completion */
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003175 if (events & IEVENT_TX_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003176 gfar_transmit(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003178 /* Check for errors */
3179 if (events & IEVENT_ERR_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003180 gfar_error(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 return IRQ_HANDLED;
3183}
3184
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185/* Called every time the controller might need to be made
3186 * aware of new link state. The PHY code conveys this
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003187 * information through variables in the phydev structure, and this
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 * function converts those variables into the appropriate
3189 * register values, and can bring down the device if needed.
3190 */
3191static void adjust_link(struct net_device *dev)
3192{
3193 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003194 struct phy_device *phydev = priv->phydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003196 if (unlikely(phydev->link != priv->oldlink ||
Guenter Roeck0ae93b22015-03-02 12:03:27 -08003197 (phydev->link && (phydev->duplex != priv->oldduplex ||
3198 phydev->speed != priv->oldspeed))))
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003199 gfar_update_link_state(priv);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003200}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
3202/* Update the hash table based on the current list of multicast
3203 * addresses we subscribe to. Also, change the promiscuity of
3204 * the device based on the flags (this function is called
Jan Ceuleers0977f812012-06-05 03:42:12 +00003205 * whenever dev->flags is changed
3206 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207static void gfar_set_multi(struct net_device *dev)
3208{
Jiri Pirko22bedad32010-04-01 21:22:57 +00003209 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003211 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 u32 tempval;
3213
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00003214 if (dev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 /* Set RCTRL to PROM */
3216 tempval = gfar_read(&regs->rctrl);
3217 tempval |= RCTRL_PROM;
3218 gfar_write(&regs->rctrl, tempval);
3219 } else {
3220 /* Set RCTRL to not PROM */
3221 tempval = gfar_read(&regs->rctrl);
3222 tempval &= ~(RCTRL_PROM);
3223 gfar_write(&regs->rctrl, tempval);
3224 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003225
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00003226 if (dev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 /* Set the hash to rx all multicast frames */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003228 gfar_write(&regs->igaddr0, 0xffffffff);
3229 gfar_write(&regs->igaddr1, 0xffffffff);
3230 gfar_write(&regs->igaddr2, 0xffffffff);
3231 gfar_write(&regs->igaddr3, 0xffffffff);
3232 gfar_write(&regs->igaddr4, 0xffffffff);
3233 gfar_write(&regs->igaddr5, 0xffffffff);
3234 gfar_write(&regs->igaddr6, 0xffffffff);
3235 gfar_write(&regs->igaddr7, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 gfar_write(&regs->gaddr0, 0xffffffff);
3237 gfar_write(&regs->gaddr1, 0xffffffff);
3238 gfar_write(&regs->gaddr2, 0xffffffff);
3239 gfar_write(&regs->gaddr3, 0xffffffff);
3240 gfar_write(&regs->gaddr4, 0xffffffff);
3241 gfar_write(&regs->gaddr5, 0xffffffff);
3242 gfar_write(&regs->gaddr6, 0xffffffff);
3243 gfar_write(&regs->gaddr7, 0xffffffff);
3244 } else {
Andy Fleming7f7f5312005-11-11 12:38:59 -06003245 int em_num;
3246 int idx;
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 /* zero out the hash */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003249 gfar_write(&regs->igaddr0, 0x0);
3250 gfar_write(&regs->igaddr1, 0x0);
3251 gfar_write(&regs->igaddr2, 0x0);
3252 gfar_write(&regs->igaddr3, 0x0);
3253 gfar_write(&regs->igaddr4, 0x0);
3254 gfar_write(&regs->igaddr5, 0x0);
3255 gfar_write(&regs->igaddr6, 0x0);
3256 gfar_write(&regs->igaddr7, 0x0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 gfar_write(&regs->gaddr0, 0x0);
3258 gfar_write(&regs->gaddr1, 0x0);
3259 gfar_write(&regs->gaddr2, 0x0);
3260 gfar_write(&regs->gaddr3, 0x0);
3261 gfar_write(&regs->gaddr4, 0x0);
3262 gfar_write(&regs->gaddr5, 0x0);
3263 gfar_write(&regs->gaddr6, 0x0);
3264 gfar_write(&regs->gaddr7, 0x0);
3265
Andy Fleming7f7f5312005-11-11 12:38:59 -06003266 /* If we have extended hash tables, we need to
3267 * clear the exact match registers to prepare for
Jan Ceuleers0977f812012-06-05 03:42:12 +00003268 * setting them
3269 */
Andy Fleming7f7f5312005-11-11 12:38:59 -06003270 if (priv->extended_hash) {
3271 em_num = GFAR_EM_NUM + 1;
3272 gfar_clear_exact_match(dev);
3273 idx = 1;
3274 } else {
3275 idx = 0;
3276 em_num = 0;
3277 }
3278
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003279 if (netdev_mc_empty(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 return;
3281
3282 /* Parse the list, and set the appropriate bits */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003283 netdev_for_each_mc_addr(ha, dev) {
Andy Fleming7f7f5312005-11-11 12:38:59 -06003284 if (idx < em_num) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003285 gfar_set_mac_for_addr(dev, idx, ha->addr);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003286 idx++;
3287 } else
Jiri Pirko22bedad32010-04-01 21:22:57 +00003288 gfar_set_hash_for_addr(dev, ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 }
3290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291}
3292
Andy Fleming7f7f5312005-11-11 12:38:59 -06003293
3294/* Clears each of the exact match registers to zero, so they
Jan Ceuleers0977f812012-06-05 03:42:12 +00003295 * don't interfere with normal reception
3296 */
Andy Fleming7f7f5312005-11-11 12:38:59 -06003297static void gfar_clear_exact_match(struct net_device *dev)
3298{
3299 int idx;
Joe Perches6a3c910c2011-11-16 09:38:02 +00003300 static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
Andy Fleming7f7f5312005-11-11 12:38:59 -06003301
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003302 for (idx = 1; idx < GFAR_EM_NUM + 1; idx++)
Joe Perchesb6bc7652010-12-21 02:16:08 -08003303 gfar_set_mac_for_addr(dev, idx, zero_arr);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003304}
3305
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306/* Set the appropriate hash bit for the given addr */
3307/* The algorithm works like so:
3308 * 1) Take the Destination Address (ie the multicast address), and
3309 * do a CRC on it (little endian), and reverse the bits of the
3310 * result.
3311 * 2) Use the 8 most significant bits as a hash into a 256-entry
3312 * table. The table is controlled through 8 32-bit registers:
3313 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
3314 * gaddr7. This means that the 3 most significant bits in the
3315 * hash index which gaddr register to use, and the 5 other bits
3316 * indicate which bit (assuming an IBM numbering scheme, which
3317 * for PowerPC (tm) is usually the case) in the register holds
Jan Ceuleers0977f812012-06-05 03:42:12 +00003318 * the entry.
3319 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
3321{
3322 u32 tempval;
3323 struct gfar_private *priv = netdev_priv(dev);
Joe Perches6a3c910c2011-11-16 09:38:02 +00003324 u32 result = ether_crc(ETH_ALEN, addr);
Kumar Gala0bbaf062005-06-20 10:54:21 -05003325 int width = priv->hash_width;
3326 u8 whichbit = (result >> (32 - width)) & 0x1f;
3327 u8 whichreg = result >> (32 - width + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 u32 value = (1 << (31-whichbit));
3329
Kumar Gala0bbaf062005-06-20 10:54:21 -05003330 tempval = gfar_read(priv->hash_regs[whichreg]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 tempval |= value;
Kumar Gala0bbaf062005-06-20 10:54:21 -05003332 gfar_write(priv->hash_regs[whichreg], tempval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
Andy Fleming7f7f5312005-11-11 12:38:59 -06003335
3336/* There are multiple MAC Address register pairs on some controllers
3337 * This function sets the numth pair to a given address
3338 */
Joe Perchesb6bc7652010-12-21 02:16:08 -08003339static void gfar_set_mac_for_addr(struct net_device *dev, int num,
3340 const u8 *addr)
Andy Fleming7f7f5312005-11-11 12:38:59 -06003341{
3342 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003343 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -06003344 u32 tempval;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003345 u32 __iomem *macptr = &regs->macstnaddr1;
Andy Fleming7f7f5312005-11-11 12:38:59 -06003346
3347 macptr += num*2;
3348
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003349 /* For a station address of 0x12345678ABCD in transmission
3350 * order (BE), MACnADDR1 is set to 0xCDAB7856 and
3351 * MACnADDR2 is set to 0x34120000.
Jan Ceuleers0977f812012-06-05 03:42:12 +00003352 */
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003353 tempval = (addr[5] << 24) | (addr[4] << 16) |
3354 (addr[3] << 8) | addr[2];
Andy Fleming7f7f5312005-11-11 12:38:59 -06003355
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003356 gfar_write(macptr, tempval);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003357
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003358 tempval = (addr[1] << 24) | (addr[0] << 16);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003359
3360 gfar_write(macptr+1, tempval);
3361}
3362
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363/* GFAR error interrupt handler */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003364static irqreturn_t gfar_error(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365{
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003366 struct gfar_priv_grp *gfargrp = grp_id;
3367 struct gfar __iomem *regs = gfargrp->regs;
3368 struct gfar_private *priv= gfargrp->priv;
3369 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 /* Save ievent for future reference */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003372 u32 events = gfar_read(&regs->ievent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 /* Clear IEVENT */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003375 gfar_write(&regs->ievent, events & IEVENT_ERR_MASK);
Scott Woodd87eb122008-07-11 18:04:45 -05003376
3377 /* Magic Packet is not an error. */
Andy Flemingb31a1d82008-12-16 15:29:15 -08003378 if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
Scott Woodd87eb122008-07-11 18:04:45 -05003379 (events & IEVENT_MAG))
3380 events &= ~IEVENT_MAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
3382 /* Hmm... */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003383 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003384 netdev_dbg(dev,
3385 "error interrupt (ievent=0x%08x imask=0x%08x)\n",
Joe Perches59deab22011-06-14 08:57:47 +00003386 events, gfar_read(&regs->imask));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
3388 /* Update the error counters */
3389 if (events & IEVENT_TXE) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003390 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
3392 if (events & IEVENT_LC)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003393 dev->stats.tx_window_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 if (events & IEVENT_CRL)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003395 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 if (events & IEVENT_XFUN) {
Anton Vorontsov836cf7f2009-11-10 14:11:08 +00003397 unsigned long flags;
3398
Joe Perches59deab22011-06-14 08:57:47 +00003399 netif_dbg(priv, tx_err, dev,
3400 "TX FIFO underrun, packet dropped\n");
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003401 dev->stats.tx_dropped++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003402 atomic64_inc(&priv->extra_stats.tx_underrun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
Anton Vorontsov836cf7f2009-11-10 14:11:08 +00003404 local_irq_save(flags);
3405 lock_tx_qs(priv);
3406
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 /* Reactivate the Tx Queues */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003408 gfar_write(&regs->tstat, gfargrp->tstat);
Anton Vorontsov836cf7f2009-11-10 14:11:08 +00003409
3410 unlock_tx_qs(priv);
3411 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 }
Joe Perches59deab22011-06-14 08:57:47 +00003413 netif_dbg(priv, tx_err, dev, "Transmit Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 }
3415 if (events & IEVENT_BSY) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003416 dev->stats.rx_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003417 atomic64_inc(&priv->extra_stats.rx_bsy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003419 gfar_receive(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
Joe Perches59deab22011-06-14 08:57:47 +00003421 netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n",
3422 gfar_read(&regs->rstat));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 }
3424 if (events & IEVENT_BABR) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003425 dev->stats.rx_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003426 atomic64_inc(&priv->extra_stats.rx_babr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
Joe Perches59deab22011-06-14 08:57:47 +00003428 netif_dbg(priv, rx_err, dev, "babbling RX error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 }
3430 if (events & IEVENT_EBERR) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05003431 atomic64_inc(&priv->extra_stats.eberr);
Joe Perches59deab22011-06-14 08:57:47 +00003432 netif_dbg(priv, rx_err, dev, "bus error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 }
Joe Perches59deab22011-06-14 08:57:47 +00003434 if (events & IEVENT_RXC)
3435 netif_dbg(priv, rx_status, dev, "control frame\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
3437 if (events & IEVENT_BABT) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05003438 atomic64_inc(&priv->extra_stats.tx_babt);
Joe Perches59deab22011-06-14 08:57:47 +00003439 netif_dbg(priv, tx_err, dev, "babbling TX error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 }
3441 return IRQ_HANDLED;
3442}
3443
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003444static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
3445{
3446 struct phy_device *phydev = priv->phydev;
3447 u32 val = 0;
3448
3449 if (!phydev->duplex)
3450 return val;
3451
3452 if (!priv->pause_aneg_en) {
3453 if (priv->tx_pause_en)
3454 val |= MACCFG1_TX_FLOW;
3455 if (priv->rx_pause_en)
3456 val |= MACCFG1_RX_FLOW;
3457 } else {
3458 u16 lcl_adv, rmt_adv;
3459 u8 flowctrl;
3460 /* get link partner capabilities */
3461 rmt_adv = 0;
3462 if (phydev->pause)
3463 rmt_adv = LPA_PAUSE_CAP;
3464 if (phydev->asym_pause)
3465 rmt_adv |= LPA_PAUSE_ASYM;
3466
Pavaluca Matei-B4661043ef8d22014-10-27 10:42:43 +02003467 lcl_adv = 0;
3468 if (phydev->advertising & ADVERTISED_Pause)
3469 lcl_adv |= ADVERTISE_PAUSE_CAP;
3470 if (phydev->advertising & ADVERTISED_Asym_Pause)
3471 lcl_adv |= ADVERTISE_PAUSE_ASYM;
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003472
3473 flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
3474 if (flowctrl & FLOW_CTRL_TX)
3475 val |= MACCFG1_TX_FLOW;
3476 if (flowctrl & FLOW_CTRL_RX)
3477 val |= MACCFG1_RX_FLOW;
3478 }
3479
3480 return val;
3481}
3482
3483static noinline void gfar_update_link_state(struct gfar_private *priv)
3484{
3485 struct gfar __iomem *regs = priv->gfargrp[0].regs;
3486 struct phy_device *phydev = priv->phydev;
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003487 struct gfar_priv_rx_q *rx_queue = NULL;
3488 int i;
3489 struct rxbd8 *bdp;
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003490
3491 if (unlikely(test_bit(GFAR_RESETTING, &priv->state)))
3492 return;
3493
3494 if (phydev->link) {
3495 u32 tempval1 = gfar_read(&regs->maccfg1);
3496 u32 tempval = gfar_read(&regs->maccfg2);
3497 u32 ecntrl = gfar_read(&regs->ecntrl);
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003498 u32 tx_flow_oldval = (tempval & MACCFG1_TX_FLOW);
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003499
3500 if (phydev->duplex != priv->oldduplex) {
3501 if (!(phydev->duplex))
3502 tempval &= ~(MACCFG2_FULL_DUPLEX);
3503 else
3504 tempval |= MACCFG2_FULL_DUPLEX;
3505
3506 priv->oldduplex = phydev->duplex;
3507 }
3508
3509 if (phydev->speed != priv->oldspeed) {
3510 switch (phydev->speed) {
3511 case 1000:
3512 tempval =
3513 ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
3514
3515 ecntrl &= ~(ECNTRL_R100);
3516 break;
3517 case 100:
3518 case 10:
3519 tempval =
3520 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
3521
3522 /* Reduced mode distinguishes
3523 * between 10 and 100
3524 */
3525 if (phydev->speed == SPEED_100)
3526 ecntrl |= ECNTRL_R100;
3527 else
3528 ecntrl &= ~(ECNTRL_R100);
3529 break;
3530 default:
3531 netif_warn(priv, link, priv->ndev,
3532 "Ack! Speed (%d) is not 10/100/1000!\n",
3533 phydev->speed);
3534 break;
3535 }
3536
3537 priv->oldspeed = phydev->speed;
3538 }
3539
3540 tempval1 &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
3541 tempval1 |= gfar_get_flowctrl_cfg(priv);
3542
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003543 /* Turn last free buffer recording on */
3544 if ((tempval1 & MACCFG1_TX_FLOW) && !tx_flow_oldval) {
3545 for (i = 0; i < priv->num_rx_queues; i++) {
3546 rx_queue = priv->rx_queue[i];
3547 bdp = rx_queue->cur_rx;
3548 /* skip to previous bd */
3549 bdp = skip_bd(bdp, rx_queue->rx_ring_size - 1,
3550 rx_queue->rx_bd_base,
3551 rx_queue->rx_ring_size);
3552
3553 if (rx_queue->rfbptr)
3554 gfar_write(rx_queue->rfbptr, (u32)bdp);
3555 }
3556
3557 priv->tx_actual_en = 1;
3558 }
3559
3560 if (unlikely(!(tempval1 & MACCFG1_TX_FLOW) && tx_flow_oldval))
3561 priv->tx_actual_en = 0;
3562
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003563 gfar_write(&regs->maccfg1, tempval1);
3564 gfar_write(&regs->maccfg2, tempval);
3565 gfar_write(&regs->ecntrl, ecntrl);
3566
3567 if (!priv->oldlink)
3568 priv->oldlink = 1;
3569
3570 } else if (priv->oldlink) {
3571 priv->oldlink = 0;
3572 priv->oldspeed = 0;
3573 priv->oldduplex = -1;
3574 }
3575
3576 if (netif_msg_link(priv))
3577 phy_print_status(phydev);
3578}
3579
Andy Flemingb31a1d82008-12-16 15:29:15 -08003580static struct of_device_id gfar_match[] =
3581{
3582 {
3583 .type = "network",
3584 .compatible = "gianfar",
3585 },
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003586 {
3587 .compatible = "fsl,etsec2",
3588 },
Andy Flemingb31a1d82008-12-16 15:29:15 -08003589 {},
3590};
Anton Vorontsove72701a2009-10-14 14:54:52 -07003591MODULE_DEVICE_TABLE(of, gfar_match);
Andy Flemingb31a1d82008-12-16 15:29:15 -08003592
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593/* Structure for a device driver */
Grant Likely74888762011-02-22 21:05:51 -07003594static struct platform_driver gfar_driver = {
Grant Likely40182942010-04-13 16:13:02 -07003595 .driver = {
3596 .name = "fsl-gianfar",
Grant Likely40182942010-04-13 16:13:02 -07003597 .pm = GFAR_PM_OPS,
3598 .of_match_table = gfar_match,
3599 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 .probe = gfar_probe,
3601 .remove = gfar_remove,
3602};
3603
Axel Lindb62f682011-11-27 16:44:17 +00003604module_platform_driver(gfar_driver);