blob: caad327e3f224a01c9accad06fc11131cb117430 [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 Hao03366a32014-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
Claudiu Manoil3d23a052015-05-06 18:07:30 +0300519static int gfar_set_mac_addr(struct net_device *dev, void *p)
520{
521 eth_mac_addr(dev, p);
522
523 gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
524
525 return 0;
526}
527
Andy Fleming26ccfc32009-03-10 12:58:28 +0000528static const struct net_device_ops gfar_netdev_ops = {
529 .ndo_open = gfar_enet_open,
530 .ndo_start_xmit = gfar_start_xmit,
531 .ndo_stop = gfar_close,
532 .ndo_change_mtu = gfar_change_mtu,
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000533 .ndo_set_features = gfar_set_features,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000534 .ndo_set_rx_mode = gfar_set_multi,
Andy Fleming26ccfc32009-03-10 12:58:28 +0000535 .ndo_tx_timeout = gfar_timeout,
536 .ndo_do_ioctl = gfar_ioctl,
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +0000537 .ndo_get_stats = gfar_get_stats,
Claudiu Manoil3d23a052015-05-06 18:07:30 +0300538 .ndo_set_mac_address = gfar_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +0000539 .ndo_validate_addr = eth_validate_addr,
Andy Fleming26ccfc32009-03-10 12:58:28 +0000540#ifdef CONFIG_NET_POLL_CONTROLLER
541 .ndo_poll_controller = gfar_netpoll,
542#endif
543};
544
Claudiu Manoilefeddce2014-02-17 12:53:17 +0200545static void gfar_ints_disable(struct gfar_private *priv)
546{
547 int i;
548 for (i = 0; i < priv->num_grps; i++) {
549 struct gfar __iomem *regs = priv->gfargrp[i].regs;
550 /* Clear IEVENT */
551 gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
552
553 /* Initialize IMASK */
554 gfar_write(&regs->imask, IMASK_INIT_CLEAR);
555 }
556}
557
558static void gfar_ints_enable(struct gfar_private *priv)
559{
560 int i;
561 for (i = 0; i < priv->num_grps; i++) {
562 struct gfar __iomem *regs = priv->gfargrp[i].regs;
563 /* Unmask the interrupts we look for */
564 gfar_write(&regs->imask, IMASK_DEFAULT);
565 }
566}
567
Claudiu Manoil84868302015-07-31 18:38:31 +0300568#ifdef CONFIG_PM
Kevin Hao91c53f762014-12-24 14:05:44 +0800569static void lock_tx_qs(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000570{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000571 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000572
573 for (i = 0; i < priv->num_tx_queues; i++)
574 spin_lock(&priv->tx_queue[i]->txlock);
575}
576
Kevin Hao91c53f762014-12-24 14:05:44 +0800577static void unlock_tx_qs(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000578{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000579 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000580
581 for (i = 0; i < priv->num_tx_queues; i++)
582 spin_unlock(&priv->tx_queue[i]->txlock);
583}
Claudiu Manoil84868302015-07-31 18:38:31 +0300584#endif
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000585
Claudiu Manoil20862782014-02-17 12:53:14 +0200586static int gfar_alloc_tx_queues(struct gfar_private *priv)
587{
588 int i;
589
590 for (i = 0; i < priv->num_tx_queues; i++) {
591 priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q),
592 GFP_KERNEL);
593 if (!priv->tx_queue[i])
594 return -ENOMEM;
595
596 priv->tx_queue[i]->tx_skbuff = NULL;
597 priv->tx_queue[i]->qindex = i;
598 priv->tx_queue[i]->dev = priv->ndev;
599 spin_lock_init(&(priv->tx_queue[i]->txlock));
600 }
601 return 0;
602}
603
604static int gfar_alloc_rx_queues(struct gfar_private *priv)
605{
606 int i;
607
608 for (i = 0; i < priv->num_rx_queues; i++) {
609 priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q),
610 GFP_KERNEL);
611 if (!priv->rx_queue[i])
612 return -ENOMEM;
613
614 priv->rx_queue[i]->rx_skbuff = NULL;
615 priv->rx_queue[i]->qindex = i;
616 priv->rx_queue[i]->dev = priv->ndev;
Claudiu Manoil20862782014-02-17 12:53:14 +0200617 }
618 return 0;
619}
620
621static void gfar_free_tx_queues(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000622{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000623 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000624
625 for (i = 0; i < priv->num_tx_queues; i++)
626 kfree(priv->tx_queue[i]);
627}
628
Claudiu Manoil20862782014-02-17 12:53:14 +0200629static void gfar_free_rx_queues(struct gfar_private *priv)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000630{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000631 int i;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000632
633 for (i = 0; i < priv->num_rx_queues; i++)
634 kfree(priv->rx_queue[i]);
635}
636
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000637static void unmap_group_regs(struct gfar_private *priv)
638{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000639 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000640
641 for (i = 0; i < MAXGROUPS; i++)
642 if (priv->gfargrp[i].regs)
643 iounmap(priv->gfargrp[i].regs);
644}
645
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000646static void free_gfar_dev(struct gfar_private *priv)
647{
648 int i, j;
649
650 for (i = 0; i < priv->num_grps; i++)
651 for (j = 0; j < GFAR_NUM_IRQS; j++) {
652 kfree(priv->gfargrp[i].irqinfo[j]);
653 priv->gfargrp[i].irqinfo[j] = NULL;
654 }
655
656 free_netdev(priv->ndev);
657}
658
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000659static void disable_napi(struct gfar_private *priv)
660{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000661 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000662
Claudiu Manoilaeb12c52014-03-07 14:42:45 +0200663 for (i = 0; i < priv->num_grps; i++) {
664 napi_disable(&priv->gfargrp[i].napi_rx);
665 napi_disable(&priv->gfargrp[i].napi_tx);
666 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000667}
668
669static void enable_napi(struct gfar_private *priv)
670{
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +0000671 int i;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000672
Claudiu Manoilaeb12c52014-03-07 14:42:45 +0200673 for (i = 0; i < priv->num_grps; i++) {
674 napi_enable(&priv->gfargrp[i].napi_rx);
675 napi_enable(&priv->gfargrp[i].napi_tx);
676 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000677}
678
679static int gfar_parse_group(struct device_node *np,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000680 struct gfar_private *priv, const char *model)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000681{
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000682 struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps];
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000683 int i;
684
Paul Gortmaker7c1e7e92013-02-04 09:49:42 +0000685 for (i = 0; i < GFAR_NUM_IRQS; i++) {
686 grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo),
687 GFP_KERNEL);
688 if (!grp->irqinfo[i])
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000689 return -ENOMEM;
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000690 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000691
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000692 grp->regs = of_iomap(np, 0);
693 if (!grp->regs)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000694 return -ENOMEM;
695
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000696 gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000697
698 /* If we aren't the FEC we have multiple interrupts */
699 if (model && strcasecmp(model, "FEC")) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000700 gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1);
701 gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2);
702 if (gfar_irq(grp, TX)->irq == NO_IRQ ||
703 gfar_irq(grp, RX)->irq == NO_IRQ ||
704 gfar_irq(grp, ER)->irq == NO_IRQ)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000705 return -EINVAL;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000706 }
707
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000708 grp->priv = priv;
709 spin_lock_init(&grp->grplock);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000710 if (priv->mode == MQ_MG_MODE) {
Jingchang Lu55917642015-03-13 10:52:32 +0200711 u32 rxq_mask, txq_mask;
712 int ret;
713
714 grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
715 grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
716
717 ret = of_property_read_u32(np, "fsl,rx-bit-map", &rxq_mask);
718 if (!ret) {
719 grp->rx_bit_map = rxq_mask ?
720 rxq_mask : (DEFAULT_MAPPING >> priv->num_grps);
721 }
722
723 ret = of_property_read_u32(np, "fsl,tx-bit-map", &txq_mask);
724 if (!ret) {
725 grp->tx_bit_map = txq_mask ?
726 txq_mask : (DEFAULT_MAPPING >> priv->num_grps);
727 }
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200728
729 if (priv->poll_mode == GFAR_SQ_POLLING) {
730 /* One Q per interrupt group: Q0 to G0, Q1 to G1 */
731 grp->rx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
732 grp->tx_bit_map = (DEFAULT_MAPPING >> priv->num_grps);
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200733 }
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000734 } else {
Claudiu Manoil5fedcc12013-01-29 03:55:11 +0000735 grp->rx_bit_map = 0xFF;
736 grp->tx_bit_map = 0xFF;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000737 }
Claudiu Manoil20862782014-02-17 12:53:14 +0200738
739 /* bit_map's MSB is q0 (from q0 to q7) but, for_each_set_bit parses
740 * right to left, so we need to revert the 8 bits to get the q index
741 */
742 grp->rx_bit_map = bitrev8(grp->rx_bit_map);
743 grp->tx_bit_map = bitrev8(grp->tx_bit_map);
744
745 /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values,
746 * also assign queues to groups
747 */
748 for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200749 if (!grp->rx_queue)
750 grp->rx_queue = priv->rx_queue[i];
Claudiu Manoil20862782014-02-17 12:53:14 +0200751 grp->num_rx_queues++;
752 grp->rstat |= (RSTAT_CLEAR_RHALT >> i);
753 priv->rqueue |= ((RQUEUE_EN0 | RQUEUE_EX0) >> i);
754 priv->rx_queue[i]->grp = grp;
755 }
756
757 for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200758 if (!grp->tx_queue)
759 grp->tx_queue = priv->tx_queue[i];
Claudiu Manoil20862782014-02-17 12:53:14 +0200760 grp->num_tx_queues++;
761 grp->tstat |= (TSTAT_CLEAR_THALT >> i);
762 priv->tqueue |= (TQUEUE_EN0 >> i);
763 priv->tx_queue[i]->grp = grp;
764 }
765
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000766 priv->num_grps++;
767
768 return 0;
769}
770
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100771static int gfar_of_group_count(struct device_node *np)
772{
773 struct device_node *child;
774 int num = 0;
775
776 for_each_available_child_of_node(np, child)
777 if (!of_node_cmp(child->name, "queue-group"))
778 num++;
779
780 return num;
781}
782
Grant Likely2dc11582010-08-06 09:25:50 -0600783static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
Andy Flemingb31a1d82008-12-16 15:29:15 -0800784{
Andy Flemingb31a1d82008-12-16 15:29:15 -0800785 const char *model;
786 const char *ctype;
787 const void *mac_addr;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000788 int err = 0, i;
789 struct net_device *dev = NULL;
790 struct gfar_private *priv = NULL;
Grant Likely61c7a082010-04-13 16:12:29 -0700791 struct device_node *np = ofdev->dev.of_node;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000792 struct device_node *child = NULL;
Jingchang Lu55917642015-03-13 10:52:32 +0200793 struct property *stash;
794 u32 stash_len = 0;
795 u32 stash_idx = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000796 unsigned int num_tx_qs, num_rx_qs;
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200797 unsigned short mode, poll_mode;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800798
Kevin Hao4b222ca2015-01-28 20:06:48 +0800799 if (!np)
Andy Flemingb31a1d82008-12-16 15:29:15 -0800800 return -ENODEV;
801
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200802 if (of_device_is_compatible(np, "fsl,etsec2")) {
803 mode = MQ_MG_MODE;
804 poll_mode = GFAR_SQ_POLLING;
805 } else {
806 mode = SQ_SG_MODE;
807 poll_mode = GFAR_SQ_POLLING;
808 }
809
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200810 if (mode == SQ_SG_MODE) {
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200811 num_tx_qs = 1;
812 num_rx_qs = 1;
813 } else { /* MQ_MG_MODE */
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200814 /* get the actual number of supported groups */
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100815 unsigned int num_grps = gfar_of_group_count(np);
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200816
817 if (num_grps == 0 || num_grps > MAXGROUPS) {
818 dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n",
819 num_grps);
820 pr_err("Cannot do alloc_etherdev, aborting\n");
821 return -EINVAL;
822 }
823
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200824 if (poll_mode == GFAR_SQ_POLLING) {
Claudiu Manoilc65d7532014-03-21 09:33:17 +0200825 num_tx_qs = num_grps; /* one txq per int group */
826 num_rx_qs = num_grps; /* one rxq per int group */
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200827 } else { /* GFAR_MQ_POLLING */
Jingchang Lu55917642015-03-13 10:52:32 +0200828 u32 tx_queues, rx_queues;
829 int ret;
830
831 /* parse the num of HW tx and rx queues */
832 ret = of_property_read_u32(np, "fsl,num_tx_queues",
833 &tx_queues);
834 num_tx_qs = ret ? 1 : tx_queues;
835
836 ret = of_property_read_u32(np, "fsl,num_rx_queues",
837 &rx_queues);
838 num_rx_qs = ret ? 1 : rx_queues;
Claudiu Manoil71ff9e32014-03-07 14:42:46 +0200839 }
840 }
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000841
842 if (num_tx_qs > MAX_TX_QS) {
Joe Perches59deab22011-06-14 08:57:47 +0000843 pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n",
844 num_tx_qs, MAX_TX_QS);
845 pr_err("Cannot do alloc_etherdev, aborting\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000846 return -EINVAL;
847 }
848
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000849 if (num_rx_qs > MAX_RX_QS) {
Joe Perches59deab22011-06-14 08:57:47 +0000850 pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n",
851 num_rx_qs, MAX_RX_QS);
852 pr_err("Cannot do alloc_etherdev, aborting\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000853 return -EINVAL;
854 }
855
856 *pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs);
857 dev = *pdev;
858 if (NULL == dev)
859 return -ENOMEM;
860
861 priv = netdev_priv(dev);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000862 priv->ndev = dev;
863
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200864 priv->mode = mode;
865 priv->poll_mode = poll_mode;
866
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000867 priv->num_tx_queues = num_tx_qs;
Ben Hutchingsfe069122010-09-27 08:27:37 +0000868 netif_set_real_num_rx_queues(dev, num_rx_qs);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000869 priv->num_rx_queues = num_rx_qs;
Claudiu Manoil20862782014-02-17 12:53:14 +0200870
871 err = gfar_alloc_tx_queues(priv);
872 if (err)
873 goto tx_alloc_failed;
874
875 err = gfar_alloc_rx_queues(priv);
876 if (err)
877 goto rx_alloc_failed;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800878
Jingchang Lu55917642015-03-13 10:52:32 +0200879 err = of_property_read_string(np, "model", &model);
880 if (err) {
881 pr_err("Device model property missing, aborting\n");
882 goto rx_alloc_failed;
883 }
884
Jan Ceuleers0977f812012-06-05 03:42:12 +0000885 /* Init Rx queue filer rule set linked list */
Sebastian Poehn4aa3a712011-06-20 13:57:59 -0700886 INIT_LIST_HEAD(&priv->rx_list.list);
887 priv->rx_list.count = 0;
888 mutex_init(&priv->rx_queue_access);
889
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000890 for (i = 0; i < MAXGROUPS; i++)
891 priv->gfargrp[i].regs = NULL;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800892
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000893 /* Parse and initialize group specific information */
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200894 if (priv->mode == MQ_MG_MODE) {
Tobias Waldekranzf50724c2015-03-05 14:48:23 +0100895 for_each_available_child_of_node(np, child) {
896 if (of_node_cmp(child->name, "queue-group"))
897 continue;
898
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000899 err = gfar_parse_group(child, priv, model);
900 if (err)
901 goto err_grp_init;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800902 }
Claudiu Manoilb338ce22014-03-11 18:01:24 +0200903 } else { /* SQ_SG_MODE */
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000904 err = gfar_parse_group(np, priv, model);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000905 if (err)
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000906 goto err_grp_init;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800907 }
908
Jingchang Lu55917642015-03-13 10:52:32 +0200909 stash = of_find_property(np, "bd-stash", NULL);
Andy Fleming4d7902f2009-02-04 16:43:44 -0800910
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000911 if (stash) {
Andy Fleming4d7902f2009-02-04 16:43:44 -0800912 priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
913 priv->bd_stash_en = 1;
914 }
915
Jingchang Lu55917642015-03-13 10:52:32 +0200916 err = of_property_read_u32(np, "rx-stash-len", &stash_len);
Andy Fleming4d7902f2009-02-04 16:43:44 -0800917
Jingchang Lu55917642015-03-13 10:52:32 +0200918 if (err == 0)
919 priv->rx_stash_size = stash_len;
Andy Fleming4d7902f2009-02-04 16:43:44 -0800920
Jingchang Lu55917642015-03-13 10:52:32 +0200921 err = of_property_read_u32(np, "rx-stash-idx", &stash_idx);
Andy Fleming4d7902f2009-02-04 16:43:44 -0800922
Jingchang Lu55917642015-03-13 10:52:32 +0200923 if (err == 0)
924 priv->rx_stash_index = stash_idx;
Andy Fleming4d7902f2009-02-04 16:43:44 -0800925
926 if (stash_len || stash_idx)
927 priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
928
Andy Flemingb31a1d82008-12-16 15:29:15 -0800929 mac_addr = of_get_mac_address(np);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000930
Andy Flemingb31a1d82008-12-16 15:29:15 -0800931 if (mac_addr)
Joe Perches6a3c9102011-11-16 09:38:02 +0000932 memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800933
934 if (model && !strcasecmp(model, "TSEC"))
Claudiu Manoil34018fd2014-02-17 12:53:15 +0200935 priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000936 FSL_GIANFAR_DEV_HAS_COALESCE |
937 FSL_GIANFAR_DEV_HAS_RMON |
938 FSL_GIANFAR_DEV_HAS_MULTI_INTR;
939
Andy Flemingb31a1d82008-12-16 15:29:15 -0800940 if (model && !strcasecmp(model, "eTSEC"))
Claudiu Manoil34018fd2014-02-17 12:53:15 +0200941 priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000942 FSL_GIANFAR_DEV_HAS_COALESCE |
943 FSL_GIANFAR_DEV_HAS_RMON |
944 FSL_GIANFAR_DEV_HAS_MULTI_INTR |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +0000945 FSL_GIANFAR_DEV_HAS_CSUM |
946 FSL_GIANFAR_DEV_HAS_VLAN |
947 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
948 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
949 FSL_GIANFAR_DEV_HAS_TIMER;
Andy Flemingb31a1d82008-12-16 15:29:15 -0800950
Jingchang Lu55917642015-03-13 10:52:32 +0200951 err = of_property_read_string(np, "phy-connection-type", &ctype);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800952
953 /* We only care about rgmii-id. The rest are autodetected */
Jingchang Lu55917642015-03-13 10:52:32 +0200954 if (err == 0 && !strcmp(ctype, "rgmii-id"))
Andy Flemingb31a1d82008-12-16 15:29:15 -0800955 priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
956 else
957 priv->interface = PHY_INTERFACE_MODE_MII;
958
Jingchang Lu55917642015-03-13 10:52:32 +0200959 if (of_find_property(np, "fsl,magic-packet", NULL))
Andy Flemingb31a1d82008-12-16 15:29:15 -0800960 priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
961
Grant Likelyfe192a42009-04-25 12:53:12 +0000962 priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800963
Florian Fainellibe403642014-05-22 09:47:48 -0700964 /* In the case of a fixed PHY, the DT node associated
965 * to the PHY is the Ethernet MAC DT node.
966 */
Uwe Kleine-König6f2c9bd2014-08-07 22:17:07 +0200967 if (!priv->phy_node && of_phy_is_fixed_link(np)) {
Florian Fainellibe403642014-05-22 09:47:48 -0700968 err = of_phy_register_fixed_link(np);
969 if (err)
970 goto err_grp_init;
971
Uwe Kleine-König6f2c9bd2014-08-07 22:17:07 +0200972 priv->phy_node = of_node_get(np);
Florian Fainellibe403642014-05-22 09:47:48 -0700973 }
974
Andy Flemingb31a1d82008-12-16 15:29:15 -0800975 /* Find the TBI PHY. If it's not there, we don't support SGMII */
Grant Likelyfe192a42009-04-25 12:53:12 +0000976 priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800977
978 return 0;
979
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000980err_grp_init:
981 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +0200982rx_alloc_failed:
983 gfar_free_rx_queues(priv);
984tx_alloc_failed:
985 gfar_free_tx_queues(priv);
Claudiu Manoilee873fd2013-01-29 03:55:12 +0000986 free_gfar_dev(priv);
Andy Flemingb31a1d82008-12-16 15:29:15 -0800987 return err;
988}
989
Ben Hutchingsca0c88c2013-11-18 23:05:27 +0000990static int gfar_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
Manfred Rudigiercc772ab2010-04-08 23:10:03 +0000991{
992 struct hwtstamp_config config;
993 struct gfar_private *priv = netdev_priv(netdev);
994
995 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
996 return -EFAULT;
997
998 /* reserved for future extensions */
999 if (config.flags)
1000 return -EINVAL;
1001
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00001002 switch (config.tx_type) {
1003 case HWTSTAMP_TX_OFF:
1004 priv->hwts_tx_en = 0;
1005 break;
1006 case HWTSTAMP_TX_ON:
1007 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
1008 return -ERANGE;
1009 priv->hwts_tx_en = 1;
1010 break;
1011 default:
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001012 return -ERANGE;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00001013 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001014
1015 switch (config.rx_filter) {
1016 case HWTSTAMP_FILTER_NONE:
Manfred Rudigier97553f72010-06-11 01:49:05 +00001017 if (priv->hwts_rx_en) {
Manfred Rudigier97553f72010-06-11 01:49:05 +00001018 priv->hwts_rx_en = 0;
Claudiu Manoil08511332014-02-24 12:13:45 +02001019 reset_gfar(netdev);
Manfred Rudigier97553f72010-06-11 01:49:05 +00001020 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001021 break;
1022 default:
1023 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
1024 return -ERANGE;
Manfred Rudigier97553f72010-06-11 01:49:05 +00001025 if (!priv->hwts_rx_en) {
Manfred Rudigier97553f72010-06-11 01:49:05 +00001026 priv->hwts_rx_en = 1;
Claudiu Manoil08511332014-02-24 12:13:45 +02001027 reset_gfar(netdev);
Manfred Rudigier97553f72010-06-11 01:49:05 +00001028 }
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001029 config.rx_filter = HWTSTAMP_FILTER_ALL;
1030 break;
1031 }
1032
1033 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1034 -EFAULT : 0;
1035}
1036
Ben Hutchingsca0c88c2013-11-18 23:05:27 +00001037static int gfar_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
1038{
1039 struct hwtstamp_config config;
1040 struct gfar_private *priv = netdev_priv(netdev);
1041
1042 config.flags = 0;
1043 config.tx_type = priv->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
1044 config.rx_filter = (priv->hwts_rx_en ?
1045 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
1046
1047 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1048 -EFAULT : 0;
1049}
1050
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001051static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1052{
1053 struct gfar_private *priv = netdev_priv(dev);
1054
1055 if (!netif_running(dev))
1056 return -EINVAL;
1057
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001058 if (cmd == SIOCSHWTSTAMP)
Ben Hutchingsca0c88c2013-11-18 23:05:27 +00001059 return gfar_hwtstamp_set(dev, rq);
1060 if (cmd == SIOCGHWTSTAMP)
1061 return gfar_hwtstamp_get(dev, rq);
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001062
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001063 if (!priv->phydev)
1064 return -ENODEV;
1065
Richard Cochran28b04112010-07-17 08:48:55 +00001066 return phy_mii_ioctl(priv->phydev, rq, cmd);
Clifford Wolf0faac9f2009-01-09 10:23:11 +00001067}
1068
Anton Vorontsov18294ad2009-11-04 12:53:00 +00001069static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar,
1070 u32 class)
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001071{
1072 u32 rqfpr = FPR_FILER_MASK;
1073 u32 rqfcr = 0x0;
1074
1075 rqfar--;
1076 rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001077 priv->ftp_rqfpr[rqfar] = rqfpr;
1078 priv->ftp_rqfcr[rqfar] = rqfcr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001079 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1080
1081 rqfar--;
1082 rqfcr = RQFCR_CMP_NOMATCH;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001083 priv->ftp_rqfpr[rqfar] = rqfpr;
1084 priv->ftp_rqfcr[rqfar] = rqfcr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001085 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1086
1087 rqfar--;
1088 rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND;
1089 rqfpr = class;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001090 priv->ftp_rqfcr[rqfar] = rqfcr;
1091 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001092 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1093
1094 rqfar--;
1095 rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND;
1096 rqfpr = class;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001097 priv->ftp_rqfcr[rqfar] = rqfcr;
1098 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001099 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1100
1101 return rqfar;
1102}
1103
1104static void gfar_init_filer_table(struct gfar_private *priv)
1105{
1106 int i = 0x0;
1107 u32 rqfar = MAX_FILER_IDX;
1108 u32 rqfcr = 0x0;
1109 u32 rqfpr = FPR_FILER_MASK;
1110
1111 /* Default rule */
1112 rqfcr = RQFCR_CMP_MATCH;
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001113 priv->ftp_rqfcr[rqfar] = rqfcr;
1114 priv->ftp_rqfpr[rqfar] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001115 gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
1116
1117 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6);
1118 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP);
1119 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP);
1120 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4);
1121 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP);
1122 rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP);
1123
Uwe Kleine-König85dd08e2010-06-11 12:16:55 +02001124 /* cur_filer_idx indicated the first non-masked rule */
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001125 priv->cur_filer_idx = rqfar;
1126
1127 /* Rest are masked rules */
1128 rqfcr = RQFCR_CMP_NOMATCH;
1129 for (i = 0; i < rqfar; i++) {
Wu Jiajun-B063786c43e042011-06-07 21:46:51 +00001130 priv->ftp_rqfcr[i] = rqfcr;
1131 priv->ftp_rqfpr[i] = rqfpr;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001132 gfar_write_filer(priv, i, rqfcr, rqfpr);
1133 }
1134}
1135
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001136#ifdef CONFIG_PPC
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001137static void __gfar_detect_errata_83xx(struct gfar_private *priv)
Anton Vorontsov7d350972010-06-30 06:39:12 +00001138{
Anton Vorontsov7d350972010-06-30 06:39:12 +00001139 unsigned int pvr = mfspr(SPRN_PVR);
1140 unsigned int svr = mfspr(SPRN_SVR);
1141 unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */
1142 unsigned int rev = svr & 0xffff;
1143
1144 /* MPC8313 Rev 2.0 and higher; All MPC837x */
1145 if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001146 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
Anton Vorontsov7d350972010-06-30 06:39:12 +00001147 priv->errata |= GFAR_ERRATA_74;
1148
Anton Vorontsovdeb90ea2010-06-30 06:39:13 +00001149 /* MPC8313 and MPC837x all rev */
1150 if ((pvr == 0x80850010 && mod == 0x80b0) ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001151 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
Anton Vorontsovdeb90ea2010-06-30 06:39:13 +00001152 priv->errata |= GFAR_ERRATA_76;
1153
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001154 /* MPC8313 Rev < 2.0 */
1155 if (pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020)
Alex Dubov4363c2f2011-03-16 17:57:13 +00001156 priv->errata |= GFAR_ERRATA_12;
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001157}
1158
1159static void __gfar_detect_errata_85xx(struct gfar_private *priv)
1160{
1161 unsigned int svr = mfspr(SPRN_SVR);
1162
1163 if ((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) == 0x20))
1164 priv->errata |= GFAR_ERRATA_12;
Claudiu Manoil53fad772013-10-09 20:20:42 +03001165 if (((SVR_SOC_VER(svr) == SVR_P2020) && (SVR_REV(svr) < 0x20)) ||
1166 ((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20)))
1167 priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001168}
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001169#endif
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001170
1171static void gfar_detect_errata(struct gfar_private *priv)
1172{
1173 struct device *dev = &priv->ofdev->dev;
1174
1175 /* no plans to fix */
1176 priv->errata |= GFAR_ERRATA_A002;
1177
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001178#ifdef CONFIG_PPC
Claudiu Manoil2969b1f2013-10-09 20:20:41 +03001179 if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2))
1180 __gfar_detect_errata_85xx(priv);
1181 else /* non-mpc85xx parts, i.e. e300 core based */
1182 __gfar_detect_errata_83xx(priv);
Claudiu Manoild6ef0bc2014-10-07 10:44:32 +03001183#endif
Alex Dubov4363c2f2011-03-16 17:57:13 +00001184
Anton Vorontsov7d350972010-06-30 06:39:12 +00001185 if (priv->errata)
1186 dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
1187 priv->errata);
1188}
1189
Claudiu Manoil08511332014-02-24 12:13:45 +02001190void gfar_mac_reset(struct gfar_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Claudiu Manoil20862782014-02-17 12:53:14 +02001192 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Claudiu Manoila328ac92014-02-24 12:13:42 +02001193 u32 tempval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 /* Reset MAC layer */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001196 gfar_write(&regs->maccfg1, MACCFG1_SOFT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Andy Flemingb98ac702009-02-04 16:38:05 -08001198 /* We need to delay at least 3 TX clocks */
Claudiu Manoila328ac92014-02-24 12:13:42 +02001199 udelay(3);
Andy Flemingb98ac702009-02-04 16:38:05 -08001200
Claudiu Manoil23402bd2013-08-12 13:53:26 +03001201 /* the soft reset bit is not self-resetting, so we need to
1202 * clear it before resuming normal operation
1203 */
Claudiu Manoil20862782014-02-17 12:53:14 +02001204 gfar_write(&regs->maccfg1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Claudiu Manoila328ac92014-02-24 12:13:42 +02001206 udelay(3);
1207
Claudiu Manoil88302642014-02-24 12:13:43 +02001208 /* Compute rx_buff_size based on config flags */
1209 gfar_rx_buff_size_config(priv);
1210
1211 /* Initialize the max receive frame/buffer lengths */
1212 gfar_write(&regs->maxfrm, priv->rx_buffer_size);
Claudiu Manoila328ac92014-02-24 12:13:42 +02001213 gfar_write(&regs->mrblr, priv->rx_buffer_size);
1214
1215 /* Initialize the Minimum Frame Length Register */
1216 gfar_write(&regs->minflr, MINFLR_INIT_SETTINGS);
1217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 /* Initialize MACCFG2. */
Anton Vorontsov7d350972010-06-30 06:39:12 +00001219 tempval = MACCFG2_INIT_SETTINGS;
Claudiu Manoil88302642014-02-24 12:13:43 +02001220
1221 /* If the mtu is larger than the max size for standard
1222 * ethernet frames (ie, a jumbo frame), then set maccfg2
1223 * to allow huge frames, and to check the length
1224 */
1225 if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE ||
1226 gfar_has_errata(priv, GFAR_ERRATA_74))
Anton Vorontsov7d350972010-06-30 06:39:12 +00001227 tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK;
Claudiu Manoil88302642014-02-24 12:13:43 +02001228
Anton Vorontsov7d350972010-06-30 06:39:12 +00001229 gfar_write(&regs->maccfg2, tempval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Claudiu Manoila328ac92014-02-24 12:13:42 +02001231 /* Clear mac addr hash registers */
1232 gfar_write(&regs->igaddr0, 0);
1233 gfar_write(&regs->igaddr1, 0);
1234 gfar_write(&regs->igaddr2, 0);
1235 gfar_write(&regs->igaddr3, 0);
1236 gfar_write(&regs->igaddr4, 0);
1237 gfar_write(&regs->igaddr5, 0);
1238 gfar_write(&regs->igaddr6, 0);
1239 gfar_write(&regs->igaddr7, 0);
1240
1241 gfar_write(&regs->gaddr0, 0);
1242 gfar_write(&regs->gaddr1, 0);
1243 gfar_write(&regs->gaddr2, 0);
1244 gfar_write(&regs->gaddr3, 0);
1245 gfar_write(&regs->gaddr4, 0);
1246 gfar_write(&regs->gaddr5, 0);
1247 gfar_write(&regs->gaddr6, 0);
1248 gfar_write(&regs->gaddr7, 0);
1249
1250 if (priv->extended_hash)
1251 gfar_clear_exact_match(priv->ndev);
1252
1253 gfar_mac_rx_config(priv);
1254
1255 gfar_mac_tx_config(priv);
1256
1257 gfar_set_mac_address(priv->ndev);
1258
1259 gfar_set_multi(priv->ndev);
1260
1261 /* clear ievent and imask before configuring coalescing */
1262 gfar_ints_disable(priv);
1263
1264 /* Configure the coalescing support */
1265 gfar_configure_coalescing_all(priv);
1266}
1267
1268static void gfar_hw_init(struct gfar_private *priv)
1269{
1270 struct gfar __iomem *regs = priv->gfargrp[0].regs;
1271 u32 attrs;
1272
1273 /* Stop the DMA engine now, in case it was running before
1274 * (The firmware could have used it, and left it running).
1275 */
1276 gfar_halt(priv);
1277
1278 gfar_mac_reset(priv);
1279
1280 /* Zero out the rmon mib registers if it has them */
1281 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
1282 memset_io(&(regs->rmon), 0, sizeof(struct rmon_mib));
1283
1284 /* Mask off the CAM interrupts */
1285 gfar_write(&regs->rmon.cam1, 0xffffffff);
1286 gfar_write(&regs->rmon.cam2, 0xffffffff);
1287 }
1288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 /* Initialize ECNTRL */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001290 gfar_write(&regs->ecntrl, ECNTRL_INIT_SETTINGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Claudiu Manoil34018fd2014-02-17 12:53:15 +02001292 /* Set the extraction length and index */
1293 attrs = ATTRELI_EL(priv->rx_stash_size) |
1294 ATTRELI_EI(priv->rx_stash_index);
1295
1296 gfar_write(&regs->attreli, attrs);
1297
1298 /* Start with defaults, and add stashing
1299 * depending on driver parameters
1300 */
1301 attrs = ATTR_INIT_SETTINGS;
1302
1303 if (priv->bd_stash_en)
1304 attrs |= ATTR_BDSTASH;
1305
1306 if (priv->rx_stash_size != 0)
1307 attrs |= ATTR_BUFSTASH;
1308
1309 gfar_write(&regs->attr, attrs);
1310
1311 /* FIFO configs */
1312 gfar_write(&regs->fifo_tx_thr, DEFAULT_FIFO_TX_THR);
1313 gfar_write(&regs->fifo_tx_starve, DEFAULT_FIFO_TX_STARVE);
1314 gfar_write(&regs->fifo_tx_starve_shutoff, DEFAULT_FIFO_TX_STARVE_OFF);
1315
Claudiu Manoil20862782014-02-17 12:53:14 +02001316 /* Program the interrupt steering regs, only for MG devices */
1317 if (priv->num_grps > 1)
1318 gfar_write_isrg(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001319}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Xiubo Li898157e2014-06-04 16:49:16 +08001321static void gfar_init_addr_hash_table(struct gfar_private *priv)
Claudiu Manoil20862782014-02-17 12:53:14 +02001322{
1323 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001324
Andy Flemingb31a1d82008-12-16 15:29:15 -08001325 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
Kumar Gala0bbaf062005-06-20 10:54:21 -05001326 priv->extended_hash = 1;
1327 priv->hash_width = 9;
1328
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001329 priv->hash_regs[0] = &regs->igaddr0;
1330 priv->hash_regs[1] = &regs->igaddr1;
1331 priv->hash_regs[2] = &regs->igaddr2;
1332 priv->hash_regs[3] = &regs->igaddr3;
1333 priv->hash_regs[4] = &regs->igaddr4;
1334 priv->hash_regs[5] = &regs->igaddr5;
1335 priv->hash_regs[6] = &regs->igaddr6;
1336 priv->hash_regs[7] = &regs->igaddr7;
1337 priv->hash_regs[8] = &regs->gaddr0;
1338 priv->hash_regs[9] = &regs->gaddr1;
1339 priv->hash_regs[10] = &regs->gaddr2;
1340 priv->hash_regs[11] = &regs->gaddr3;
1341 priv->hash_regs[12] = &regs->gaddr4;
1342 priv->hash_regs[13] = &regs->gaddr5;
1343 priv->hash_regs[14] = &regs->gaddr6;
1344 priv->hash_regs[15] = &regs->gaddr7;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001345
1346 } else {
1347 priv->extended_hash = 0;
1348 priv->hash_width = 8;
1349
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001350 priv->hash_regs[0] = &regs->gaddr0;
1351 priv->hash_regs[1] = &regs->gaddr1;
1352 priv->hash_regs[2] = &regs->gaddr2;
1353 priv->hash_regs[3] = &regs->gaddr3;
1354 priv->hash_regs[4] = &regs->gaddr4;
1355 priv->hash_regs[5] = &regs->gaddr5;
1356 priv->hash_regs[6] = &regs->gaddr6;
1357 priv->hash_regs[7] = &regs->gaddr7;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001358 }
Claudiu Manoil20862782014-02-17 12:53:14 +02001359}
1360
1361/* Set up the ethernet device structure, private data,
1362 * and anything else we need before we start
1363 */
1364static int gfar_probe(struct platform_device *ofdev)
1365{
1366 struct net_device *dev = NULL;
1367 struct gfar_private *priv = NULL;
1368 int err = 0, i;
1369
1370 err = gfar_of_init(ofdev, &dev);
1371
1372 if (err)
1373 return err;
1374
1375 priv = netdev_priv(dev);
1376 priv->ndev = dev;
1377 priv->ofdev = ofdev;
1378 priv->dev = &ofdev->dev;
1379 SET_NETDEV_DEV(dev, &ofdev->dev);
1380
1381 spin_lock_init(&priv->bflock);
1382 INIT_WORK(&priv->reset_task, gfar_reset_task);
1383
1384 platform_set_drvdata(ofdev, priv);
1385
1386 gfar_detect_errata(priv);
1387
Claudiu Manoil20862782014-02-17 12:53:14 +02001388 /* Set the dev->base_addr to the gfar reg region */
1389 dev->base_addr = (unsigned long) priv->gfargrp[0].regs;
1390
1391 /* Fill in the dev structure */
1392 dev->watchdog_timeo = TX_TIMEOUT;
1393 dev->mtu = 1500;
1394 dev->netdev_ops = &gfar_netdev_ops;
1395 dev->ethtool_ops = &gfar_ethtool_ops;
1396
1397 /* Register for napi ...We are registering NAPI for each grp */
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02001398 for (i = 0; i < priv->num_grps; i++) {
1399 if (priv->poll_mode == GFAR_SQ_POLLING) {
1400 netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
1401 gfar_poll_rx_sq, GFAR_DEV_WEIGHT);
1402 netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
1403 gfar_poll_tx_sq, 2);
1404 } else {
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02001405 netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
1406 gfar_poll_rx, GFAR_DEV_WEIGHT);
1407 netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
1408 gfar_poll_tx, 2);
1409 }
1410 }
Claudiu Manoil20862782014-02-17 12:53:14 +02001411
1412 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
1413 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
1414 NETIF_F_RXCSUM;
1415 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG |
1416 NETIF_F_RXCSUM | NETIF_F_HIGHDMA;
1417 }
1418
1419 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
1420 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX |
1421 NETIF_F_HW_VLAN_CTAG_RX;
1422 dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1423 }
1424
Claudiu Manoil3d23a052015-05-06 18:07:30 +03001425 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
1426
Claudiu Manoil20862782014-02-17 12:53:14 +02001427 gfar_init_addr_hash_table(priv);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001428
Claudiu Manoil532c37b2014-02-17 12:53:16 +02001429 /* Insert receive time stamps into padding alignment bytes */
1430 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
1431 priv->padding = 8;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001432
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00001433 if (dev->features & NETIF_F_IP_CSUM ||
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001434 priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
Wu Jiajun-B06378bee9e582012-05-21 23:00:48 +00001435 dev->needed_headroom = GMAC_FCB_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
1437 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001439 /* Initializing some of the rx/tx queue level parameters */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001440 for (i = 0; i < priv->num_tx_queues; i++) {
1441 priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE;
1442 priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE;
1443 priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE;
1444 priv->tx_queue[i]->txic = DEFAULT_TXIC;
1445 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001446
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001447 for (i = 0; i < priv->num_rx_queues; i++) {
1448 priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE;
1449 priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE;
1450 priv->rx_queue[i]->rxic = DEFAULT_RXIC;
1451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Jan Ceuleers0977f812012-06-05 03:42:12 +00001453 /* always enable rx filer */
Sebastian Poehn4aa3a712011-06-20 13:57:59 -07001454 priv->rx_filer_enable = 1;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001455 /* Enable most messages by default */
1456 priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
Claudiu Manoilb98b8ba2012-09-23 22:39:08 +00001457 /* use pritority h/w tx queue scheduling for single queue devices */
1458 if (priv->num_tx_queues == 1)
1459 priv->prio_sched_en = 1;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001460
Claudiu Manoil08511332014-02-24 12:13:45 +02001461 set_bit(GFAR_DOWN, &priv->state);
1462
Claudiu Manoila328ac92014-02-24 12:13:42 +02001463 gfar_hw_init(priv);
Trent Piephod3eab822008-10-02 11:12:24 +00001464
Fabio Estevamd4c642e2014-06-03 19:55:38 -03001465 /* Carrier starts down, phylib will bring it up */
1466 netif_carrier_off(dev);
1467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 err = register_netdev(dev);
1469
1470 if (err) {
Joe Perches59deab22011-06-14 08:57:47 +00001471 pr_err("%s: Cannot register net device, aborting\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 goto register_fail;
1473 }
1474
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08001475 device_init_wakeup(&dev->dev,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001476 priv->device_flags &
1477 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08001478
Dai Harukic50a5d92008-12-17 16:51:32 -08001479 /* fill out IRQ number and name fields */
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001480 for (i = 0; i < priv->num_grps; i++) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001481 struct gfar_priv_grp *grp = &priv->gfargrp[i];
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001482 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001483 sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001484 dev->name, "_g", '0' + i, "_tx");
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001485 sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001486 dev->name, "_g", '0' + i, "_rx");
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001487 sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s",
Joe Perches0015e552012-03-25 07:10:07 +00001488 dev->name, "_g", '0' + i, "_er");
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001489 } else
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001490 strcpy(gfar_irq(grp, TX)->name, dev->name);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001491 }
Dai Harukic50a5d92008-12-17 16:51:32 -08001492
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +00001493 /* Initialize the filer table */
1494 gfar_init_filer_table(priv);
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 /* Print out the device info */
Joe Perches59deab22011-06-14 08:57:47 +00001497 netdev_info(dev, "mac: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Jan Ceuleers0977f812012-06-05 03:42:12 +00001499 /* Even more device info helps when determining which kernel
1500 * provided which set of benchmarks.
1501 */
Joe Perches59deab22011-06-14 08:57:47 +00001502 netdev_info(dev, "Running with NAPI enabled\n");
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001503 for (i = 0; i < priv->num_rx_queues; i++)
Joe Perches59deab22011-06-14 08:57:47 +00001504 netdev_info(dev, "RX BD ring size for Q[%d]: %d\n",
1505 i, priv->rx_queue[i]->rx_ring_size);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001506 for (i = 0; i < priv->num_tx_queues; i++)
Joe Perches59deab22011-06-14 08:57:47 +00001507 netdev_info(dev, "TX BD ring size for Q[%d]: %d\n",
1508 i, priv->tx_queue[i]->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 return 0;
1511
1512register_fail:
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001513 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001514 gfar_free_rx_queues(priv);
1515 gfar_free_tx_queues(priv);
Uwe Kleine-König888c88b2014-08-07 21:20:12 +02001516 of_node_put(priv->phy_node);
1517 of_node_put(priv->tbi_node);
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001518 free_gfar_dev(priv);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001519 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Grant Likely2dc11582010-08-06 09:25:50 -06001522static int gfar_remove(struct platform_device *ofdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Jingoo Han8513fbd2013-05-23 00:52:31 +00001524 struct gfar_private *priv = platform_get_drvdata(ofdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Uwe Kleine-König888c88b2014-08-07 21:20:12 +02001526 of_node_put(priv->phy_node);
1527 of_node_put(priv->tbi_node);
Grant Likelyfe192a42009-04-25 12:53:12 +00001528
David S. Millerd9d8e042009-09-06 01:41:02 -07001529 unregister_netdev(priv->ndev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001530 unmap_group_regs(priv);
Claudiu Manoil20862782014-02-17 12:53:14 +02001531 gfar_free_rx_queues(priv);
1532 gfar_free_tx_queues(priv);
Claudiu Manoilee873fd2013-01-29 03:55:12 +00001533 free_gfar_dev(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 return 0;
1536}
1537
Scott Woodd87eb122008-07-11 18:04:45 -05001538#ifdef CONFIG_PM
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001539
1540static int gfar_suspend(struct device *dev)
Scott Woodd87eb122008-07-11 18:04:45 -05001541{
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001542 struct gfar_private *priv = dev_get_drvdata(dev);
1543 struct net_device *ndev = priv->ndev;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001544 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001545 unsigned long flags;
1546 u32 tempval;
1547
1548 int magic_packet = priv->wol_en &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001549 (priv->device_flags &
1550 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Scott Woodd87eb122008-07-11 18:04:45 -05001551
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001552 netif_device_detach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001553
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001554 if (netif_running(ndev)) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001555
1556 local_irq_save(flags);
1557 lock_tx_qs(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001558
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001559 gfar_halt_nodisable(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001560
1561 /* Disable Tx, and Rx if wake-on-LAN is disabled. */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001562 tempval = gfar_read(&regs->maccfg1);
Scott Woodd87eb122008-07-11 18:04:45 -05001563
1564 tempval &= ~MACCFG1_TX_EN;
1565
1566 if (!magic_packet)
1567 tempval &= ~MACCFG1_RX_EN;
1568
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001569 gfar_write(&regs->maccfg1, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001570
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001571 unlock_tx_qs(priv);
1572 local_irq_restore(flags);
Scott Woodd87eb122008-07-11 18:04:45 -05001573
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001574 disable_napi(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001575
1576 if (magic_packet) {
1577 /* Enable interrupt on Magic Packet */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001578 gfar_write(&regs->imask, IMASK_MAG);
Scott Woodd87eb122008-07-11 18:04:45 -05001579
1580 /* Enable Magic Packet mode */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001581 tempval = gfar_read(&regs->maccfg2);
Scott Woodd87eb122008-07-11 18:04:45 -05001582 tempval |= MACCFG2_MPEN;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001583 gfar_write(&regs->maccfg2, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001584 } else {
1585 phy_stop(priv->phydev);
1586 }
1587 }
1588
1589 return 0;
1590}
1591
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001592static int gfar_resume(struct device *dev)
Scott Woodd87eb122008-07-11 18:04:45 -05001593{
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001594 struct gfar_private *priv = dev_get_drvdata(dev);
1595 struct net_device *ndev = priv->ndev;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001596 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001597 unsigned long flags;
1598 u32 tempval;
1599 int magic_packet = priv->wol_en &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001600 (priv->device_flags &
1601 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
Scott Woodd87eb122008-07-11 18:04:45 -05001602
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001603 if (!netif_running(ndev)) {
1604 netif_device_attach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001605 return 0;
1606 }
1607
1608 if (!magic_packet && priv->phydev)
1609 phy_start(priv->phydev);
1610
1611 /* Disable Magic Packet mode, in case something
1612 * else woke us up.
1613 */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001614 local_irq_save(flags);
1615 lock_tx_qs(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001616
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001617 tempval = gfar_read(&regs->maccfg2);
Scott Woodd87eb122008-07-11 18:04:45 -05001618 tempval &= ~MACCFG2_MPEN;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001619 gfar_write(&regs->maccfg2, tempval);
Scott Woodd87eb122008-07-11 18:04:45 -05001620
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001621 gfar_start(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001622
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001623 unlock_tx_qs(priv);
1624 local_irq_restore(flags);
Scott Woodd87eb122008-07-11 18:04:45 -05001625
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001626 netif_device_attach(ndev);
Scott Woodd87eb122008-07-11 18:04:45 -05001627
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001628 enable_napi(priv);
Scott Woodd87eb122008-07-11 18:04:45 -05001629
1630 return 0;
1631}
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001632
1633static int gfar_restore(struct device *dev)
1634{
1635 struct gfar_private *priv = dev_get_drvdata(dev);
1636 struct net_device *ndev = priv->ndev;
1637
Wang Dongsheng103cdd12012-11-09 04:43:51 +00001638 if (!netif_running(ndev)) {
1639 netif_device_attach(ndev);
1640
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001641 return 0;
Wang Dongsheng103cdd12012-11-09 04:43:51 +00001642 }
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001643
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001644 if (gfar_init_bds(ndev)) {
1645 free_skb_resources(priv);
1646 return -ENOMEM;
1647 }
1648
Claudiu Manoila328ac92014-02-24 12:13:42 +02001649 gfar_mac_reset(priv);
1650
1651 gfar_init_tx_rx_base(priv);
1652
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001653 gfar_start(priv);
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001654
1655 priv->oldlink = 0;
1656 priv->oldspeed = 0;
1657 priv->oldduplex = -1;
1658
1659 if (priv->phydev)
1660 phy_start(priv->phydev);
1661
1662 netif_device_attach(ndev);
Anton Vorontsov5ea681d2009-11-10 14:11:05 +00001663 enable_napi(priv);
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001664
1665 return 0;
1666}
1667
1668static struct dev_pm_ops gfar_pm_ops = {
1669 .suspend = gfar_suspend,
1670 .resume = gfar_resume,
1671 .freeze = gfar_suspend,
1672 .thaw = gfar_resume,
1673 .restore = gfar_restore,
1674};
1675
1676#define GFAR_PM_OPS (&gfar_pm_ops)
1677
Scott Woodd87eb122008-07-11 18:04:45 -05001678#else
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001679
1680#define GFAR_PM_OPS NULL
Anton Vorontsovbe926fc2009-10-12 06:00:42 +00001681
Scott Woodd87eb122008-07-11 18:04:45 -05001682#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001684/* Reads the controller's registers to determine what interface
1685 * connects it to the PHY.
1686 */
1687static phy_interface_t gfar_get_interface(struct net_device *dev)
1688{
1689 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001690 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001691 u32 ecntrl;
1692
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001693 ecntrl = gfar_read(&regs->ecntrl);
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001694
1695 if (ecntrl & ECNTRL_SGMII_MODE)
1696 return PHY_INTERFACE_MODE_SGMII;
1697
1698 if (ecntrl & ECNTRL_TBI_MODE) {
1699 if (ecntrl & ECNTRL_REDUCED_MODE)
1700 return PHY_INTERFACE_MODE_RTBI;
1701 else
1702 return PHY_INTERFACE_MODE_TBI;
1703 }
1704
1705 if (ecntrl & ECNTRL_REDUCED_MODE) {
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001706 if (ecntrl & ECNTRL_REDUCED_MII_MODE) {
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001707 return PHY_INTERFACE_MODE_RMII;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001708 }
Andy Fleming7132ab72007-07-11 11:43:07 -05001709 else {
Andy Flemingb31a1d82008-12-16 15:29:15 -08001710 phy_interface_t interface = priv->interface;
Andy Fleming7132ab72007-07-11 11:43:07 -05001711
Jan Ceuleers0977f812012-06-05 03:42:12 +00001712 /* This isn't autodetected right now, so it must
Andy Fleming7132ab72007-07-11 11:43:07 -05001713 * be set by the device tree or platform code.
1714 */
1715 if (interface == PHY_INTERFACE_MODE_RGMII_ID)
1716 return PHY_INTERFACE_MODE_RGMII_ID;
1717
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001718 return PHY_INTERFACE_MODE_RGMII;
Andy Fleming7132ab72007-07-11 11:43:07 -05001719 }
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001720 }
1721
Andy Flemingb31a1d82008-12-16 15:29:15 -08001722 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001723 return PHY_INTERFACE_MODE_GMII;
1724
1725 return PHY_INTERFACE_MODE_MII;
1726}
1727
1728
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001729/* Initializes driver's PHY state, and attaches to the PHY.
1730 * Returns 0 on success.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 */
1732static int init_phy(struct net_device *dev)
1733{
1734 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001735 uint gigabit_support =
Andy Flemingb31a1d82008-12-16 15:29:15 -08001736 priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
Claudiu Manoil23402bd2013-08-12 13:53:26 +03001737 GFAR_SUPPORTED_GBIT : 0;
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001738 phy_interface_t interface;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 priv->oldlink = 0;
1741 priv->oldspeed = 0;
1742 priv->oldduplex = -1;
1743
Andy Fleminge8a2b6a2006-12-01 12:01:06 -06001744 interface = gfar_get_interface(dev);
1745
Anton Vorontsov1db780f2009-07-16 21:31:42 +00001746 priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
1747 interface);
Anton Vorontsov1db780f2009-07-16 21:31:42 +00001748 if (!priv->phydev) {
1749 dev_err(&dev->dev, "could not attach to PHY\n");
1750 return -ENODEV;
Grant Likelyfe192a42009-04-25 12:53:12 +00001751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Kapil Junejad3c12872007-05-11 18:25:11 -05001753 if (interface == PHY_INTERFACE_MODE_SGMII)
1754 gfar_configure_serdes(dev);
1755
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001756 /* Remove any features not supported by the controller */
Grant Likelyfe192a42009-04-25 12:53:12 +00001757 priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
1758 priv->phydev->advertising = priv->phydev->supported;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Pavaluca Matei-B46610cf987af2014-10-27 10:42:42 +02001760 /* Add support for flow control, but don't advertise it by default */
1761 priv->phydev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
1765
Jan Ceuleers0977f812012-06-05 03:42:12 +00001766/* Initialize TBI PHY interface for communicating with the
Paul Gortmakerd0313582008-04-17 00:08:10 -04001767 * SERDES lynx PHY on the chip. We communicate with this PHY
1768 * through the MDIO bus on each controller, treating it as a
1769 * "normal" PHY at the address found in the TBIPA register. We assume
1770 * that the TBIPA register is valid. Either the MDIO bus code will set
1771 * it to a value that doesn't conflict with other PHYs on the bus, or the
1772 * value doesn't matter, as there are no other PHYs on the bus.
1773 */
Kapil Junejad3c12872007-05-11 18:25:11 -05001774static void gfar_configure_serdes(struct net_device *dev)
1775{
1776 struct gfar_private *priv = netdev_priv(dev);
Grant Likelyfe192a42009-04-25 12:53:12 +00001777 struct phy_device *tbiphy;
Trent Piephoc1324192008-10-30 18:17:06 -07001778
Grant Likelyfe192a42009-04-25 12:53:12 +00001779 if (!priv->tbi_node) {
1780 dev_warn(&dev->dev, "error: SGMII mode requires that the "
1781 "device tree specify a tbi-handle\n");
1782 return;
1783 }
1784
1785 tbiphy = of_phy_find_device(priv->tbi_node);
1786 if (!tbiphy) {
1787 dev_err(&dev->dev, "error: Could not get TBI device\n");
Andy Flemingb31a1d82008-12-16 15:29:15 -08001788 return;
1789 }
Kapil Junejad3c12872007-05-11 18:25:11 -05001790
Jan Ceuleers0977f812012-06-05 03:42:12 +00001791 /* If the link is already up, we must already be ok, and don't need to
Trent Piephobdb59f92008-10-30 18:17:07 -07001792 * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
1793 * everything for us? Resetting it takes the link down and requires
1794 * several seconds for it to come back.
1795 */
Grant Likelyfe192a42009-04-25 12:53:12 +00001796 if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
Andy Flemingb31a1d82008-12-16 15:29:15 -08001797 return;
Kapil Junejad3c12872007-05-11 18:25:11 -05001798
Paul Gortmakerd0313582008-04-17 00:08:10 -04001799 /* Single clk mode, mii mode off(for serdes communication) */
Grant Likelyfe192a42009-04-25 12:53:12 +00001800 phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
Kapil Junejad3c12872007-05-11 18:25:11 -05001801
Grant Likelyfe192a42009-04-25 12:53:12 +00001802 phy_write(tbiphy, MII_ADVERTISE,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001803 ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
1804 ADVERTISE_1000XPSE_ASYM);
Kapil Junejad3c12872007-05-11 18:25:11 -05001805
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001806 phy_write(tbiphy, MII_BMCR,
1807 BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX |
1808 BMCR_SPEED1000);
Kapil Junejad3c12872007-05-11 18:25:11 -05001809}
1810
Anton Vorontsov511d9342010-06-30 06:39:15 +00001811static int __gfar_is_rx_idle(struct gfar_private *priv)
1812{
1813 u32 res;
1814
Jan Ceuleers0977f812012-06-05 03:42:12 +00001815 /* Normaly TSEC should not hang on GRS commands, so we should
Anton Vorontsov511d9342010-06-30 06:39:15 +00001816 * actually wait for IEVENT_GRSC flag.
1817 */
Claudiu Manoilad3660c2013-10-09 20:20:40 +03001818 if (!gfar_has_errata(priv, GFAR_ERRATA_A002))
Anton Vorontsov511d9342010-06-30 06:39:15 +00001819 return 0;
1820
Jan Ceuleers0977f812012-06-05 03:42:12 +00001821 /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are
Anton Vorontsov511d9342010-06-30 06:39:15 +00001822 * the same as bits 23-30, the eTSEC Rx is assumed to be idle
1823 * and the Rx can be safely reset.
1824 */
1825 res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c);
1826 res &= 0x7f807f80;
1827 if ((res & 0xffff) == (res >> 16))
1828 return 1;
1829
1830 return 0;
1831}
Kumar Gala0bbaf062005-06-20 10:54:21 -05001832
1833/* Halt the receive and transmit queues */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001834static void gfar_halt_nodisable(struct gfar_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
Claudiu Manoilefeddce2014-02-17 12:53:17 +02001836 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 u32 tempval;
Claudiu Manoila4feee82014-10-07 10:44:34 +03001838 unsigned int timeout;
1839 int stopped;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Claudiu Manoilefeddce2014-02-17 12:53:17 +02001841 gfar_ints_disable(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Claudiu Manoila4feee82014-10-07 10:44:34 +03001843 if (gfar_is_dma_stopped(priv))
1844 return;
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 /* Stop the DMA, and wait for it to stop */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00001847 tempval = gfar_read(&regs->dmactrl);
Claudiu Manoila4feee82014-10-07 10:44:34 +03001848 tempval |= (DMACTRL_GRS | DMACTRL_GTS);
1849 gfar_write(&regs->dmactrl, tempval);
Anton Vorontsov511d9342010-06-30 06:39:15 +00001850
Claudiu Manoila4feee82014-10-07 10:44:34 +03001851retry:
1852 timeout = 1000;
1853 while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) {
1854 cpu_relax();
1855 timeout--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
Claudiu Manoila4feee82014-10-07 10:44:34 +03001857
1858 if (!timeout)
1859 stopped = gfar_is_dma_stopped(priv);
1860
1861 if (!stopped && !gfar_is_rx_dma_stopped(priv) &&
1862 !__gfar_is_rx_idle(priv))
1863 goto retry;
Scott Woodd87eb122008-07-11 18:04:45 -05001864}
Scott Woodd87eb122008-07-11 18:04:45 -05001865
1866/* Halt the receive and transmit queues */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001867void gfar_halt(struct gfar_private *priv)
Scott Woodd87eb122008-07-11 18:04:45 -05001868{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001869 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Scott Woodd87eb122008-07-11 18:04:45 -05001870 u32 tempval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001872 /* Dissable the Rx/Tx hw queues */
1873 gfar_write(&regs->rqueue, 0);
1874 gfar_write(&regs->tqueue, 0);
Scott Wood2a54adc2008-08-12 15:10:46 -05001875
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001876 mdelay(10);
1877
1878 gfar_halt_nodisable(priv);
1879
1880 /* Disable Rx/Tx DMA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 tempval = gfar_read(&regs->maccfg1);
1882 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
1883 gfar_write(&regs->maccfg1, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001884}
1885
1886void stop_gfar(struct net_device *dev)
1887{
1888 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001889
Claudiu Manoil08511332014-02-24 12:13:45 +02001890 netif_tx_stop_all_queues(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04001891
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001892 smp_mb__before_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02001893 set_bit(GFAR_DOWN, &priv->state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01001894 smp_mb__after_atomic();
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001895
Claudiu Manoil08511332014-02-24 12:13:45 +02001896 disable_napi(priv);
Kumar Gala0bbaf062005-06-20 10:54:21 -05001897
Claudiu Manoil08511332014-02-24 12:13:45 +02001898 /* disable ints and gracefully shut down Rx/Tx DMA */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001899 gfar_halt(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Claudiu Manoil08511332014-02-24 12:13:45 +02001901 phy_stop(priv->phydev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 free_skb_resources(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001906static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 struct txbd8 *txbdp;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001909 struct gfar_private *priv = netdev_priv(tx_queue->dev);
Dai Haruki4669bc92008-12-17 16:51:04 -08001910 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001912 txbdp = tx_queue->tx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001914 for (i = 0; i < tx_queue->tx_ring_size; i++) {
1915 if (!tx_queue->tx_skbuff[i])
Dai Haruki4669bc92008-12-17 16:51:04 -08001916 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Claudiu Manoila7312d52015-03-13 10:36:28 +02001918 dma_unmap_single(priv->dev, be32_to_cpu(txbdp->bufPtr),
1919 be16_to_cpu(txbdp->length), DMA_TO_DEVICE);
Dai Haruki4669bc92008-12-17 16:51:04 -08001920 txbdp->lstatus = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001921 for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001922 j++) {
Dai Haruki4669bc92008-12-17 16:51:04 -08001923 txbdp++;
Claudiu Manoila7312d52015-03-13 10:36:28 +02001924 dma_unmap_page(priv->dev, be32_to_cpu(txbdp->bufPtr),
1925 be16_to_cpu(txbdp->length),
1926 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
Andy Flemingad5da7a2008-05-07 13:20:55 -05001928 txbdp++;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001929 dev_kfree_skb_any(tx_queue->tx_skbuff[i]);
1930 tx_queue->tx_skbuff[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001932 kfree(tx_queue->tx_skbuff);
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001933 tx_queue->tx_skbuff = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001934}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001936static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
1937{
1938 struct rxbd8 *rxbdp;
1939 struct gfar_private *priv = netdev_priv(rx_queue->dev);
1940 int i;
1941
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001942 rxbdp = rx_queue->rx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001944 for (i = 0; i < rx_queue->rx_ring_size; i++) {
1945 if (rx_queue->rx_skbuff[i]) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02001946 dma_unmap_single(priv->dev, be32_to_cpu(rxbdp->bufPtr),
Claudiu Manoil369ec162013-02-14 05:00:02 +00001947 priv->rx_buffer_size,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001948 DMA_FROM_DEVICE);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001949 dev_kfree_skb_any(rx_queue->rx_skbuff[i]);
1950 rx_queue->rx_skbuff[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 }
Anton Vorontsove69edd22009-10-12 06:00:30 +00001952 rxbdp->lstatus = 0;
1953 rxbdp->bufPtr = 0;
1954 rxbdp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 }
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00001956 kfree(rx_queue->rx_skbuff);
Claudiu Manoil1eb8f7a2012-11-08 22:11:41 +00001957 rx_queue->rx_skbuff = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001958}
Anton Vorontsove69edd22009-10-12 06:00:30 +00001959
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001960/* If there are any tx skbs or rx skbs still around, free them.
Jan Ceuleers0977f812012-06-05 03:42:12 +00001961 * Then free tx_skbuff and rx_skbuff
1962 */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001963static void free_skb_resources(struct gfar_private *priv)
1964{
1965 struct gfar_priv_tx_q *tx_queue = NULL;
1966 struct gfar_priv_rx_q *rx_queue = NULL;
1967 int i;
1968
1969 /* Go through all the buffer descriptors and free their data buffers */
1970 for (i = 0; i < priv->num_tx_queues; i++) {
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001971 struct netdev_queue *txq;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001972
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001973 tx_queue = priv->tx_queue[i];
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001974 txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001975 if (tx_queue->tx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001976 free_skb_tx_queue(tx_queue);
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05001977 netdev_tx_reset_queue(txq);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001978 }
1979
1980 for (i = 0; i < priv->num_rx_queues; i++) {
1981 rx_queue = priv->rx_queue[i];
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001982 if (rx_queue->rx_skbuff)
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00001983 free_skb_rx_queue(rx_queue);
1984 }
1985
Claudiu Manoil369ec162013-02-14 05:00:02 +00001986 dma_free_coherent(priv->dev,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00001987 sizeof(struct txbd8) * priv->total_tx_ring_size +
1988 sizeof(struct rxbd8) * priv->total_rx_ring_size,
1989 priv->tx_queue[0]->tx_bd_base,
1990 priv->tx_queue[0]->tx_bd_dma_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991}
1992
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001993void gfar_start(struct gfar_private *priv)
Kumar Gala0bbaf062005-06-20 10:54:21 -05001994{
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001995 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001996 u32 tempval;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00001997 int i = 0;
Kumar Gala0bbaf062005-06-20 10:54:21 -05001998
Claudiu Manoilc10650b2014-02-17 12:53:18 +02001999 /* Enable Rx/Tx hw queues */
2000 gfar_write(&regs->rqueue, priv->rqueue);
2001 gfar_write(&regs->tqueue, priv->tqueue);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002002
2003 /* Initialize DMACTRL to have WWR and WOP */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002004 tempval = gfar_read(&regs->dmactrl);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002005 tempval |= DMACTRL_INIT_SETTINGS;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002006 gfar_write(&regs->dmactrl, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002007
Kumar Gala0bbaf062005-06-20 10:54:21 -05002008 /* Make sure we aren't stopped */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002009 tempval = gfar_read(&regs->dmactrl);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002010 tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002011 gfar_write(&regs->dmactrl, tempval);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002012
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002013 for (i = 0; i < priv->num_grps; i++) {
2014 regs = priv->gfargrp[i].regs;
2015 /* Clear THLT/RHLT, so that the DMA starts polling now */
2016 gfar_write(&regs->tstat, priv->gfargrp[i].tstat);
2017 gfar_write(&regs->rstat, priv->gfargrp[i].rstat);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002018 }
Dai Haruki12dea572008-12-16 15:30:20 -08002019
Claudiu Manoilc10650b2014-02-17 12:53:18 +02002020 /* Enable Rx/Tx DMA */
2021 tempval = gfar_read(&regs->maccfg1);
2022 tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
2023 gfar_write(&regs->maccfg1, tempval);
2024
Claudiu Manoilefeddce2014-02-17 12:53:17 +02002025 gfar_ints_enable(priv);
2026
Claudiu Manoilc10650b2014-02-17 12:53:18 +02002027 priv->ndev->trans_start = jiffies; /* prevent tx timeout */
Kumar Gala0bbaf062005-06-20 10:54:21 -05002028}
2029
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002030static void free_grp_irqs(struct gfar_priv_grp *grp)
2031{
2032 free_irq(gfar_irq(grp, TX)->irq, grp);
2033 free_irq(gfar_irq(grp, RX)->irq, grp);
2034 free_irq(gfar_irq(grp, ER)->irq, grp);
2035}
2036
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002037static int register_grp_irqs(struct gfar_priv_grp *grp)
2038{
2039 struct gfar_private *priv = grp->priv;
2040 struct net_device *dev = priv->ndev;
Anton Vorontsovccc05c62009-10-12 06:00:26 +00002041 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 /* If the device has multiple interrupts, register for
Jan Ceuleers0977f812012-06-05 03:42:12 +00002044 * them. Otherwise, only register for the one
2045 */
Andy Flemingb31a1d82008-12-16 15:29:15 -08002046 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Kumar Gala0bbaf062005-06-20 10:54:21 -05002047 /* Install our interrupt handlers for Error,
Jan Ceuleers0977f812012-06-05 03:42:12 +00002048 * Transmit, and Receive
2049 */
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002050 err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0,
2051 gfar_irq(grp, ER)->name, grp);
2052 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002053 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002054 gfar_irq(grp, ER)->irq);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002055
Julia Lawall2145f1a2010-08-05 10:26:20 +00002056 goto err_irq_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 }
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002058 err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0,
2059 gfar_irq(grp, TX)->name, grp);
2060 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002061 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002062 gfar_irq(grp, TX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 goto tx_irq_fail;
2064 }
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002065 err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0,
2066 gfar_irq(grp, RX)->name, grp);
2067 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002068 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002069 gfar_irq(grp, RX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 goto rx_irq_fail;
2071 }
2072 } else {
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002073 err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0,
2074 gfar_irq(grp, TX)->name, grp);
2075 if (err < 0) {
Joe Perches59deab22011-06-14 08:57:47 +00002076 netif_err(priv, intr, dev, "Can't get IRQ %d\n",
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002077 gfar_irq(grp, TX)->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 goto err_irq_fail;
2079 }
2080 }
2081
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002082 return 0;
2083
2084rx_irq_fail:
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002085 free_irq(gfar_irq(grp, TX)->irq, grp);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002086tx_irq_fail:
Claudiu Manoilee873fd2013-01-29 03:55:12 +00002087 free_irq(gfar_irq(grp, ER)->irq, grp);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002088err_irq_fail:
2089 return err;
2090
2091}
2092
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002093static void gfar_free_irq(struct gfar_private *priv)
2094{
2095 int i;
2096
2097 /* Free the IRQs */
2098 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
2099 for (i = 0; i < priv->num_grps; i++)
2100 free_grp_irqs(&priv->gfargrp[i]);
2101 } else {
2102 for (i = 0; i < priv->num_grps; i++)
2103 free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq,
2104 &priv->gfargrp[i]);
2105 }
2106}
2107
2108static int gfar_request_irq(struct gfar_private *priv)
2109{
2110 int err, i, j;
2111
2112 for (i = 0; i < priv->num_grps; i++) {
2113 err = register_grp_irqs(&priv->gfargrp[i]);
2114 if (err) {
2115 for (j = 0; j < i; j++)
2116 free_grp_irqs(&priv->gfargrp[j]);
2117 return err;
2118 }
2119 }
2120
2121 return 0;
2122}
2123
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002124/* Bring the controller up and running */
2125int startup_gfar(struct net_device *ndev)
2126{
2127 struct gfar_private *priv = netdev_priv(ndev);
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002128 int err;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002129
Claudiu Manoila328ac92014-02-24 12:13:42 +02002130 gfar_mac_reset(priv);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002131
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002132 err = gfar_alloc_skb_resources(ndev);
2133 if (err)
2134 return err;
2135
Claudiu Manoila328ac92014-02-24 12:13:42 +02002136 gfar_init_tx_rx_base(priv);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002137
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002138 smp_mb__before_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02002139 clear_bit(GFAR_DOWN, &priv->state);
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002140 smp_mb__after_atomic();
Claudiu Manoil08511332014-02-24 12:13:45 +02002141
2142 /* Start Rx/Tx DMA and enable the interrupts */
Claudiu Manoilc10650b2014-02-17 12:53:18 +02002143 gfar_start(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Anton Vorontsov826aa4a2009-10-12 06:00:34 +00002145 phy_start(priv->phydev);
2146
Claudiu Manoil08511332014-02-24 12:13:45 +02002147 enable_napi(priv);
2148
2149 netif_tx_wake_all_queues(ndev);
2150
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
Jan Ceuleers0977f812012-06-05 03:42:12 +00002154/* Called when something needs to use the ethernet device
2155 * Returns 0 for success.
2156 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157static int gfar_enet_open(struct net_device *dev)
2158{
Li Yang94e8cc32007-10-12 21:53:51 +08002159 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 int err;
2161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 err = init_phy(dev);
Claudiu Manoil08511332014-02-24 12:13:45 +02002163 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 return err;
2165
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002166 err = gfar_request_irq(priv);
2167 if (err)
2168 return err;
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 err = startup_gfar(dev);
Claudiu Manoil08511332014-02-24 12:13:45 +02002171 if (err)
Anton Vorontsovdb0e8e32007-10-17 23:57:46 +04002172 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Anton Vorontsov2884e5c2009-02-01 00:52:34 -08002174 device_set_wakeup_enable(&dev->dev, priv->wol_en);
2175
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 return err;
2177}
2178
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002179static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002180{
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002181 struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
Kumar Gala6c31d552009-04-28 08:04:10 -07002182
2183 memset(fcb, 0, GMAC_FCB_LEN);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002184
Kumar Gala0bbaf062005-06-20 10:54:21 -05002185 return fcb;
2186}
2187
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002188static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002189 int fcb_length)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002190{
Kumar Gala0bbaf062005-06-20 10:54:21 -05002191 /* If we're here, it's a IP packet with a TCP or UDP
2192 * payload. We set it to checksum, using a pseudo-header
2193 * we provide
2194 */
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +00002195 u8 flags = TXFCB_DEFAULT;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002196
Jan Ceuleers0977f812012-06-05 03:42:12 +00002197 /* Tell the controller what the protocol is
2198 * And provide the already calculated phcs
2199 */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002200 if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
Andy Fleming7f7f5312005-11-11 12:38:59 -06002201 flags |= TXFCB_UDP;
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002202 fcb->phcs = (__force __be16)(udp_hdr(skb)->check);
Andy Fleming7f7f5312005-11-11 12:38:59 -06002203 } else
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002204 fcb->phcs = (__force __be16)(tcp_hdr(skb)->check);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002205
2206 /* l3os is the distance between the start of the
2207 * frame (skb->data) and the start of the IP hdr.
2208 * l4os is the distance between the start of the
Jan Ceuleers0977f812012-06-05 03:42:12 +00002209 * l3 hdr and the l4 hdr
2210 */
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002211 fcb->l3os = (u8)(skb_network_offset(skb) - fcb_length);
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -03002212 fcb->l4os = skb_network_header_len(skb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002213
Andy Fleming7f7f5312005-11-11 12:38:59 -06002214 fcb->flags = flags;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002215}
2216
Andy Fleming7f7f5312005-11-11 12:38:59 -06002217void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
Kumar Gala0bbaf062005-06-20 10:54:21 -05002218{
Andy Fleming7f7f5312005-11-11 12:38:59 -06002219 fcb->flags |= TXFCB_VLN;
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002220 fcb->vlctl = cpu_to_be16(skb_vlan_tag_get(skb));
Kumar Gala0bbaf062005-06-20 10:54:21 -05002221}
2222
Dai Haruki4669bc92008-12-17 16:51:04 -08002223static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002224 struct txbd8 *base, int ring_size)
Dai Haruki4669bc92008-12-17 16:51:04 -08002225{
2226 struct txbd8 *new_bd = bdp + stride;
2227
2228 return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
2229}
2230
2231static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002232 int ring_size)
Dai Haruki4669bc92008-12-17 16:51:04 -08002233{
2234 return skip_txbd(bdp, 1, base, ring_size);
2235}
2236
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002237/* eTSEC12: csum generation not supported for some fcb offsets */
2238static inline bool gfar_csum_errata_12(struct gfar_private *priv,
2239 unsigned long fcb_addr)
2240{
2241 return (gfar_has_errata(priv, GFAR_ERRATA_12) &&
2242 (fcb_addr % 0x20) > 0x18);
2243}
2244
2245/* eTSEC76: csum generation for frames larger than 2500 may
2246 * cause excess delays before start of transmission
2247 */
2248static inline bool gfar_csum_errata_76(struct gfar_private *priv,
2249 unsigned int len)
2250{
2251 return (gfar_has_errata(priv, GFAR_ERRATA_76) &&
2252 (len > 2500));
2253}
2254
Jan Ceuleers0977f812012-06-05 03:42:12 +00002255/* This is called by the kernel when a frame is ready for transmission.
2256 * It is pointed to by the dev->hard_start_xmit function pointer
2257 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2259{
2260 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002261 struct gfar_priv_tx_q *tx_queue = NULL;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002262 struct netdev_queue *txq;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002263 struct gfar __iomem *regs = NULL;
Kumar Gala0bbaf062005-06-20 10:54:21 -05002264 struct txfcb *fcb = NULL;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002265 struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL;
Dai Haruki5a5efed2008-12-16 15:34:50 -08002266 u32 lstatus;
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002267 int i, rq = 0;
2268 int do_tstamp, do_csum, do_vlan;
Dai Haruki4669bc92008-12-17 16:51:04 -08002269 u32 bufaddr;
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002270 unsigned int nr_frags, nr_txbds, bytes_sent, fcb_len = 0;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002271
2272 rq = skb->queue_mapping;
2273 tx_queue = priv->tx_queue[rq];
2274 txq = netdev_get_tx_queue(dev, rq);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002275 base = tx_queue->tx_bd_base;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00002276 regs = tx_queue->grp->regs;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002277
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002278 do_csum = (CHECKSUM_PARTIAL == skb->ip_summed);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01002279 do_vlan = skb_vlan_tag_present(skb);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002280 do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
2281 priv->hwts_tx_en;
2282
2283 if (do_csum || do_vlan)
2284 fcb_len = GMAC_FCB_LEN;
2285
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002286 /* check if time stamp should be generated */
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002287 if (unlikely(do_tstamp))
2288 fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
Dai Haruki4669bc92008-12-17 16:51:04 -08002289
Li Yang5b28bea2009-03-27 15:54:30 -07002290 /* make space for additional header when fcb is needed */
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002291 if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) {
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002292 struct sk_buff *skb_new;
2293
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002294 skb_new = skb_realloc_headroom(skb, fcb_len);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002295 if (!skb_new) {
2296 dev->stats.tx_errors++;
Eric W. Biedermanc9974ad2014-03-11 14:20:26 -07002297 dev_kfree_skb_any(skb);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002298 return NETDEV_TX_OK;
2299 }
Manfred Rudigierdb83d132012-01-09 23:26:50 +00002300
Eric Dumazet313b0372012-07-05 11:45:13 +00002301 if (skb->sk)
2302 skb_set_owner_w(skb_new, skb->sk);
Eric W. Biedermanc9974ad2014-03-11 14:20:26 -07002303 dev_consume_skb_any(skb);
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002304 skb = skb_new;
2305 }
2306
Dai Haruki4669bc92008-12-17 16:51:04 -08002307 /* total number of fragments in the SKB */
2308 nr_frags = skb_shinfo(skb)->nr_frags;
2309
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002310 /* calculate the required number of TxBDs for this skb */
2311 if (unlikely(do_tstamp))
2312 nr_txbds = nr_frags + 2;
2313 else
2314 nr_txbds = nr_frags + 1;
2315
Dai Haruki4669bc92008-12-17 16:51:04 -08002316 /* check if there is space to queue this packet */
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002317 if (nr_txbds > tx_queue->num_txbdfree) {
Dai Haruki4669bc92008-12-17 16:51:04 -08002318 /* no space, stop the queue */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002319 netif_tx_stop_queue(txq);
Dai Haruki4669bc92008-12-17 16:51:04 -08002320 dev->stats.tx_fifo_errors++;
Dai Haruki4669bc92008-12-17 16:51:04 -08002321 return NETDEV_TX_BUSY;
2322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324 /* Update transmit stats */
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002325 bytes_sent = skb->len;
2326 tx_queue->stats.tx_bytes += bytes_sent;
2327 /* keep Tx bytes on wire for BQL accounting */
2328 GFAR_CB(skb)->bytes_sent = bytes_sent;
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00002329 tx_queue->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002331 txbdp = txbdp_start = tx_queue->cur_tx;
Claudiu Manoila7312d52015-03-13 10:36:28 +02002332 lstatus = be32_to_cpu(txbdp->lstatus);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002333
2334 /* Time stamp insertion requires one additional TxBD */
2335 if (unlikely(do_tstamp))
2336 txbdp_tstamp = txbdp = next_txbd(txbdp, base,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002337 tx_queue->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Dai Haruki4669bc92008-12-17 16:51:04 -08002339 if (nr_frags == 0) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002340 if (unlikely(do_tstamp)) {
2341 u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus);
2342
2343 lstatus_ts |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
2344 txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts);
2345 } else {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002346 lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002347 }
Dai Haruki4669bc92008-12-17 16:51:04 -08002348 } else {
2349 /* Place the fragment addresses and lengths into the TxBDs */
2350 for (i = 0; i < nr_frags; i++) {
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002351 unsigned int frag_len;
Dai Haruki4669bc92008-12-17 16:51:04 -08002352 /* Point at the next BD, wrapping as needed */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002353 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002355 frag_len = skb_shinfo(skb)->frags[i].size;
Dai Haruki4669bc92008-12-17 16:51:04 -08002356
Claudiu Manoila7312d52015-03-13 10:36:28 +02002357 lstatus = be32_to_cpu(txbdp->lstatus) | frag_len |
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002358 BD_LFLAG(TXBD_READY);
Dai Haruki4669bc92008-12-17 16:51:04 -08002359
2360 /* Handle the last BD specially */
2361 if (i == nr_frags - 1)
2362 lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
2363
Claudiu Manoil369ec162013-02-14 05:00:02 +00002364 bufaddr = skb_frag_dma_map(priv->dev,
Ian Campbell2234a722011-08-29 23:18:29 +00002365 &skb_shinfo(skb)->frags[i],
2366 0,
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002367 frag_len,
Ian Campbell2234a722011-08-29 23:18:29 +00002368 DMA_TO_DEVICE);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002369 if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
2370 goto dma_map_err;
Dai Haruki4669bc92008-12-17 16:51:04 -08002371
2372 /* set the TxBD length and buffer pointer */
Claudiu Manoila7312d52015-03-13 10:36:28 +02002373 txbdp->bufPtr = cpu_to_be32(bufaddr);
2374 txbdp->lstatus = cpu_to_be32(lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002375 }
2376
Claudiu Manoila7312d52015-03-13 10:36:28 +02002377 lstatus = be32_to_cpu(txbdp_start->lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002380 /* Add TxPAL between FCB and frame if required */
2381 if (unlikely(do_tstamp)) {
2382 skb_push(skb, GMAC_TXPAL_LEN);
2383 memset(skb->data, 0, GMAC_TXPAL_LEN);
2384 }
2385
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002386 /* Add TxFCB if required */
2387 if (fcb_len) {
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002388 fcb = gfar_add_fcb(skb);
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002389 lstatus |= BD_LFLAG(TXBD_TOE);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002390 }
2391
2392 /* Set up checksumming */
2393 if (do_csum) {
2394 gfar_tx_checksum(skb, fcb, fcb_len);
Claudiu Manoil02d88fb2013-08-05 17:20:09 +03002395
2396 if (unlikely(gfar_csum_errata_12(priv, (unsigned long)fcb)) ||
2397 unlikely(gfar_csum_errata_76(priv, skb->len))) {
Alex Dubov4363c2f2011-03-16 17:57:13 +00002398 __skb_pull(skb, GMAC_FCB_LEN);
2399 skb_checksum_help(skb);
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002400 if (do_vlan || do_tstamp) {
2401 /* put back a new fcb for vlan/tstamp TOE */
2402 fcb = gfar_add_fcb(skb);
2403 } else {
2404 /* Tx TOE not used */
2405 lstatus &= ~(BD_LFLAG(TXBD_TOE));
2406 fcb = NULL;
2407 }
Alex Dubov4363c2f2011-03-16 17:57:13 +00002408 }
Kumar Gala0bbaf062005-06-20 10:54:21 -05002409 }
2410
Claudiu Manoil0d0cffd2013-08-05 17:20:10 +03002411 if (do_vlan)
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002412 gfar_tx_vlan(skb, fcb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002413
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002414 /* Setup tx hardware time stamping if requested */
2415 if (unlikely(do_tstamp)) {
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002416 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002417 fcb->ptp = 1;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002418 }
2419
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002420 bufaddr = dma_map_single(priv->dev, skb->data, skb_headlen(skb),
2421 DMA_TO_DEVICE);
2422 if (unlikely(dma_mapping_error(priv->dev, bufaddr)))
2423 goto dma_map_err;
2424
Claudiu Manoila7312d52015-03-13 10:36:28 +02002425 txbdp_start->bufPtr = cpu_to_be32(bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Jan Ceuleers0977f812012-06-05 03:42:12 +00002427 /* If time stamping is requested one additional TxBD must be set up. The
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002428 * first TxBD points to the FCB and must have a data length of
2429 * GMAC_FCB_LEN. The second TxBD points to the actual frame data with
2430 * the full frame length.
2431 */
2432 if (unlikely(do_tstamp)) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002433 u32 lstatus_ts = be32_to_cpu(txbdp_tstamp->lstatus);
2434
2435 bufaddr = be32_to_cpu(txbdp_start->bufPtr);
2436 bufaddr += fcb_len;
2437 lstatus_ts |= BD_LFLAG(TXBD_READY) |
2438 (skb_headlen(skb) - fcb_len);
2439
2440 txbdp_tstamp->bufPtr = cpu_to_be32(bufaddr);
2441 txbdp_tstamp->lstatus = cpu_to_be32(lstatus_ts);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002442 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
2443 } else {
2444 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002447 netdev_tx_sent_queue(txq, bytes_sent);
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002448
Claudiu Manoild55398b2014-10-07 10:44:35 +03002449 gfar_wmb();
Andy Fleming7f7f5312005-11-11 12:38:59 -06002450
Claudiu Manoila7312d52015-03-13 10:36:28 +02002451 txbdp_start->lstatus = cpu_to_be32(lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002452
Claudiu Manoild55398b2014-10-07 10:44:35 +03002453 gfar_wmb(); /* force lstatus write before tx_skbuff */
Anton Vorontsov0eddba52010-03-03 08:18:58 +00002454
2455 tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb;
2456
Dai Haruki4669bc92008-12-17 16:51:04 -08002457 /* Update the current skb pointer to the next entry we will use
Jan Ceuleers0977f812012-06-05 03:42:12 +00002458 * (wrapping if necessary)
2459 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002460 tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) &
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002461 TX_RING_MOD_MASK(tx_queue->tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002462
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002463 tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002464
Claudiu Manoilbc602282015-05-06 18:07:29 +03002465 /* We can work in parallel with gfar_clean_tx_ring(), except
2466 * when modifying num_txbdfree. Note that we didn't grab the lock
2467 * when we were reading the num_txbdfree and checking for available
2468 * space, that's because outside of this function it can only grow.
2469 */
2470 spin_lock_bh(&tx_queue->txlock);
Dai Haruki4669bc92008-12-17 16:51:04 -08002471 /* reduce TxBD free count */
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002472 tx_queue->num_txbdfree -= (nr_txbds);
Claudiu Manoilbc602282015-05-06 18:07:29 +03002473 spin_unlock_bh(&tx_queue->txlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 /* If the next BD still needs to be cleaned up, then the bds
Jan Ceuleers0977f812012-06-05 03:42:12 +00002476 * are full. We need to tell the kernel to stop sending us stuff.
2477 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002478 if (!tx_queue->num_txbdfree) {
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002479 netif_tx_stop_queue(txq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002481 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 }
2483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 /* Tell the DMA to go go go */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00002485 gfar_write(&regs->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Stephen Hemminger54dc79f2009-03-27 00:38:45 -07002487 return NETDEV_TX_OK;
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002488
2489dma_map_err:
2490 txbdp = next_txbd(txbdp_start, base, tx_queue->tx_ring_size);
2491 if (do_tstamp)
2492 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
2493 for (i = 0; i < nr_frags; i++) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002494 lstatus = be32_to_cpu(txbdp->lstatus);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002495 if (!(lstatus & BD_LFLAG(TXBD_READY)))
2496 break;
2497
Claudiu Manoila7312d52015-03-13 10:36:28 +02002498 lstatus &= ~BD_LFLAG(TXBD_READY);
2499 txbdp->lstatus = cpu_to_be32(lstatus);
2500 bufaddr = be32_to_cpu(txbdp->bufPtr);
2501 dma_unmap_page(priv->dev, bufaddr, be16_to_cpu(txbdp->length),
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002502 DMA_TO_DEVICE);
2503 txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
2504 }
2505 gfar_wmb();
2506 dev_kfree_skb_any(skb);
2507 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
2509
2510/* Stops the kernel queue, and halts the controller */
2511static int gfar_close(struct net_device *dev)
2512{
2513 struct gfar_private *priv = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002514
Sebastian Siewiorab939902008-08-19 21:12:45 +02002515 cancel_work_sync(&priv->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 stop_gfar(dev);
2517
Andy Flemingbb40dcb2005-09-23 22:54:21 -04002518 /* Disconnect from the PHY */
2519 phy_disconnect(priv->phydev);
2520 priv->phydev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Claudiu Manoil80ec3962014-02-24 12:13:44 +02002522 gfar_free_irq(priv);
2523
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 return 0;
2525}
2526
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527/* Changes the mac address if the controller is not running. */
Andy Flemingf162b9d2008-05-02 13:00:30 -05002528static int gfar_set_mac_address(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529{
Andy Fleming7f7f5312005-11-11 12:38:59 -06002530 gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 return 0;
2533}
2534
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535static int gfar_change_mtu(struct net_device *dev, int new_mtu)
2536{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002538 int frame_size = new_mtu + ETH_HLEN;
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
Joe Perches59deab22011-06-14 08:57:47 +00002541 netif_err(priv, drv, dev, "Invalid MTU setting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 return -EINVAL;
2543 }
2544
Claudiu Manoil08511332014-02-24 12:13:45 +02002545 while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
2546 cpu_relax();
2547
Claudiu Manoil88302642014-02-24 12:13:43 +02002548 if (dev->flags & IFF_UP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 stop_gfar(dev);
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 dev->mtu = new_mtu;
2552
Claudiu Manoil88302642014-02-24 12:13:43 +02002553 if (dev->flags & IFF_UP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 startup_gfar(dev);
2555
Claudiu Manoil08511332014-02-24 12:13:45 +02002556 clear_bit_unlock(GFAR_RESETTING, &priv->state);
2557
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 return 0;
2559}
2560
Claudiu Manoil08511332014-02-24 12:13:45 +02002561void reset_gfar(struct net_device *ndev)
2562{
2563 struct gfar_private *priv = netdev_priv(ndev);
2564
2565 while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state))
2566 cpu_relax();
2567
2568 stop_gfar(ndev);
2569 startup_gfar(ndev);
2570
2571 clear_bit_unlock(GFAR_RESETTING, &priv->state);
2572}
2573
Sebastian Siewiorab939902008-08-19 21:12:45 +02002574/* gfar_reset_task gets scheduled when a packet has not been
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 * transmitted after a set amount of time.
2576 * For now, assume that clearing out all the structures, and
Sebastian Siewiorab939902008-08-19 21:12:45 +02002577 * starting over will fix the problem.
2578 */
2579static void gfar_reset_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
Sebastian Siewiorab939902008-08-19 21:12:45 +02002581 struct gfar_private *priv = container_of(work, struct gfar_private,
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002582 reset_task);
Claudiu Manoil08511332014-02-24 12:13:45 +02002583 reset_gfar(priv->ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584}
2585
Sebastian Siewiorab939902008-08-19 21:12:45 +02002586static void gfar_timeout(struct net_device *dev)
2587{
2588 struct gfar_private *priv = netdev_priv(dev);
2589
2590 dev->stats.tx_errors++;
2591 schedule_work(&priv->reset_task);
2592}
2593
Eran Libertyacbc0f02010-07-07 15:54:54 -07002594static void gfar_align_skb(struct sk_buff *skb)
2595{
2596 /* We need the data buffer to be aligned properly. We will reserve
2597 * as many bytes as needed to align the data properly
2598 */
2599 skb_reserve(skb, RXBUF_ALIGNMENT -
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002600 (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1)));
Eran Libertyacbc0f02010-07-07 15:54:54 -07002601}
2602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603/* Interrupt Handler for Transmit complete */
Claudiu Manoilc233cf402013-03-19 07:40:02 +00002604static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002606 struct net_device *dev = tx_queue->dev;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002607 struct netdev_queue *txq;
Dai Harukid080cd62008-04-09 19:37:51 -05002608 struct gfar_private *priv = netdev_priv(dev);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002609 struct txbd8 *bdp, *next = NULL;
Dai Haruki4669bc92008-12-17 16:51:04 -08002610 struct txbd8 *lbdp = NULL;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002611 struct txbd8 *base = tx_queue->tx_bd_base;
Dai Haruki4669bc92008-12-17 16:51:04 -08002612 struct sk_buff *skb;
2613 int skb_dirtytx;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002614 int tx_ring_size = tx_queue->tx_ring_size;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002615 int frags = 0, nr_txbds = 0;
Dai Haruki4669bc92008-12-17 16:51:04 -08002616 int i;
Dai Harukid080cd62008-04-09 19:37:51 -05002617 int howmany = 0;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002618 int tqi = tx_queue->qindex;
2619 unsigned int bytes_sent = 0;
Dai Haruki4669bc92008-12-17 16:51:04 -08002620 u32 lstatus;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002621 size_t buflen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002623 txq = netdev_get_tx_queue(dev, tqi);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002624 bdp = tx_queue->dirty_tx;
2625 skb_dirtytx = tx_queue->skb_dirtytx;
Dai Haruki4669bc92008-12-17 16:51:04 -08002626
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002627 while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) {
Anton Vorontsova3bc1f12009-11-10 14:11:10 +00002628
Dai Haruki4669bc92008-12-17 16:51:04 -08002629 frags = skb_shinfo(skb)->nr_frags;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002630
Jan Ceuleers0977f812012-06-05 03:42:12 +00002631 /* When time stamping, one additional TxBD must be freed.
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002632 * Also, we need to dma_unmap_single() the TxPAL.
2633 */
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002634 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002635 nr_txbds = frags + 2;
2636 else
2637 nr_txbds = frags + 1;
2638
2639 lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002640
Claudiu Manoila7312d52015-03-13 10:36:28 +02002641 lstatus = be32_to_cpu(lbdp->lstatus);
Dai Haruki4669bc92008-12-17 16:51:04 -08002642
2643 /* Only clean completed frames */
2644 if ((lstatus & BD_LFLAG(TXBD_READY)) &&
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002645 (lstatus & BD_LENGTH_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 break;
2647
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002648 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002649 next = next_txbd(bdp, base, tx_ring_size);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002650 buflen = be16_to_cpu(next->length) +
2651 GMAC_FCB_LEN + GMAC_TXPAL_LEN;
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002652 } else
Claudiu Manoila7312d52015-03-13 10:36:28 +02002653 buflen = be16_to_cpu(bdp->length);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002654
Claudiu Manoila7312d52015-03-13 10:36:28 +02002655 dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr),
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002656 buflen, DMA_TO_DEVICE);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002657
Oliver Hartkopp2244d072010-08-17 08:59:14 +00002658 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002659 struct skb_shared_hwtstamps shhwtstamps;
2660 u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7);
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002661
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002662 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
2663 shhwtstamps.hwtstamp = ns_to_ktime(*ns);
Manfred Rudigier9c4886e2012-01-09 23:26:51 +00002664 skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002665 skb_tstamp_tx(skb, &shhwtstamps);
Claudiu Manoila7312d52015-03-13 10:36:28 +02002666 gfar_clear_txbd_status(bdp);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002667 bdp = next;
2668 }
Dai Haruki4669bc92008-12-17 16:51:04 -08002669
Claudiu Manoila7312d52015-03-13 10:36:28 +02002670 gfar_clear_txbd_status(bdp);
Dai Haruki4669bc92008-12-17 16:51:04 -08002671 bdp = next_txbd(bdp, base, tx_ring_size);
2672
2673 for (i = 0; i < frags; i++) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002674 dma_unmap_page(priv->dev, be32_to_cpu(bdp->bufPtr),
2675 be16_to_cpu(bdp->length),
2676 DMA_TO_DEVICE);
2677 gfar_clear_txbd_status(bdp);
Dai Haruki4669bc92008-12-17 16:51:04 -08002678 bdp = next_txbd(bdp, base, tx_ring_size);
2679 }
2680
Claudiu Manoil50ad0762013-08-30 15:01:15 +03002681 bytes_sent += GFAR_CB(skb)->bytes_sent;
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002682
Eric Dumazetacb600d2012-10-05 06:23:55 +00002683 dev_kfree_skb_any(skb);
Andy Fleming0fd56bb2009-02-04 16:43:16 -08002684
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002685 tx_queue->tx_skbuff[skb_dirtytx] = NULL;
Dai Haruki4669bc92008-12-17 16:51:04 -08002686
2687 skb_dirtytx = (skb_dirtytx + 1) &
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002688 TX_RING_MOD_MASK(tx_ring_size);
Dai Haruki4669bc92008-12-17 16:51:04 -08002689
Dai Harukid080cd62008-04-09 19:37:51 -05002690 howmany++;
Claudiu Manoilbc602282015-05-06 18:07:29 +03002691 spin_lock(&tx_queue->txlock);
Manfred Rudigierf0ee7ac2010-04-08 23:10:35 +00002692 tx_queue->num_txbdfree += nr_txbds;
Claudiu Manoilbc602282015-05-06 18:07:29 +03002693 spin_unlock(&tx_queue->txlock);
Dai Haruki4669bc92008-12-17 16:51:04 -08002694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Dai Haruki4669bc92008-12-17 16:51:04 -08002696 /* If we freed a buffer, we can restart transmission, if necessary */
Claudiu Manoil08511332014-02-24 12:13:45 +02002697 if (tx_queue->num_txbdfree &&
2698 netif_tx_queue_stopped(txq) &&
2699 !(test_bit(GFAR_DOWN, &priv->state)))
2700 netif_wake_subqueue(priv->ndev, tqi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
Dai Haruki4669bc92008-12-17 16:51:04 -08002702 /* Update dirty indicators */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002703 tx_queue->skb_dirtytx = skb_dirtytx;
2704 tx_queue->dirty_tx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
Paul Gortmakerd8a0f1b2012-01-06 13:51:03 -05002706 netdev_tx_completed_queue(txq, howmany, bytes_sent);
Dai Harukid080cd62008-04-09 19:37:51 -05002707}
2708
Jan Ceuleers2281a0f2012-06-05 03:42:11 +00002709static struct sk_buff *gfar_alloc_skb(struct net_device *dev)
Eran Libertyacbc0f02010-07-07 15:54:54 -07002710{
2711 struct gfar_private *priv = netdev_priv(dev);
Eric Dumazetacb600d2012-10-05 06:23:55 +00002712 struct sk_buff *skb;
Eran Libertyacbc0f02010-07-07 15:54:54 -07002713
2714 skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
2715 if (!skb)
2716 return NULL;
2717
2718 gfar_align_skb(skb);
2719
2720 return skb;
2721}
Andy Fleming815b97c2008-04-22 17:18:29 -05002722
Kevin Hao91c53f762014-12-24 14:05:44 +08002723static struct sk_buff *gfar_new_skb(struct net_device *dev, dma_addr_t *bufaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724{
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002725 struct gfar_private *priv = netdev_priv(dev);
2726 struct sk_buff *skb;
2727 dma_addr_t addr;
2728
2729 skb = gfar_alloc_skb(dev);
2730 if (!skb)
2731 return NULL;
2732
2733 addr = dma_map_single(priv->dev, skb->data,
2734 priv->rx_buffer_size, DMA_FROM_DEVICE);
2735 if (unlikely(dma_mapping_error(priv->dev, addr))) {
2736 dev_kfree_skb_any(skb);
2737 return NULL;
2738 }
2739
2740 *bufaddr = addr;
2741 return skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742}
2743
Li Yang298e1a92007-10-16 14:18:13 +08002744static inline void count_errors(unsigned short status, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745{
Li Yang298e1a92007-10-16 14:18:13 +08002746 struct gfar_private *priv = netdev_priv(dev);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002747 struct net_device_stats *stats = &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 struct gfar_extra_stats *estats = &priv->extra_stats;
2749
Jan Ceuleers0977f812012-06-05 03:42:12 +00002750 /* If the packet was truncated, none of the other errors matter */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 if (status & RXBD_TRUNCATED) {
2752 stats->rx_length_errors++;
2753
Paul Gortmaker212079d2013-02-12 15:38:19 -05002754 atomic64_inc(&estats->rx_trunc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
2756 return;
2757 }
2758 /* Count the errors, if there were any */
2759 if (status & (RXBD_LARGE | RXBD_SHORT)) {
2760 stats->rx_length_errors++;
2761
2762 if (status & RXBD_LARGE)
Paul Gortmaker212079d2013-02-12 15:38:19 -05002763 atomic64_inc(&estats->rx_large);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 else
Paul Gortmaker212079d2013-02-12 15:38:19 -05002765 atomic64_inc(&estats->rx_short);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 }
2767 if (status & RXBD_NONOCTET) {
2768 stats->rx_frame_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05002769 atomic64_inc(&estats->rx_nonoctet);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 }
2771 if (status & RXBD_CRCERR) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05002772 atomic64_inc(&estats->rx_crcerr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 stats->rx_crc_errors++;
2774 }
2775 if (status & RXBD_OVERRUN) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05002776 atomic64_inc(&estats->rx_overrun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 stats->rx_crc_errors++;
2778 }
2779}
2780
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00002781irqreturn_t gfar_receive(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782{
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002783 struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
2784 unsigned long flags;
2785 u32 imask;
2786
2787 if (likely(napi_schedule_prep(&grp->napi_rx))) {
2788 spin_lock_irqsave(&grp->grplock, flags);
2789 imask = gfar_read(&grp->regs->imask);
2790 imask &= IMASK_RX_DISABLED;
2791 gfar_write(&grp->regs->imask, imask);
2792 spin_unlock_irqrestore(&grp->grplock, flags);
2793 __napi_schedule(&grp->napi_rx);
2794 } else {
2795 /* Clear IEVENT, so interrupts aren't called again
2796 * because of the packets that have already arrived.
2797 */
2798 gfar_write(&grp->regs->ievent, IEVENT_RX_MASK);
2799 }
2800
2801 return IRQ_HANDLED;
2802}
2803
2804/* Interrupt Handler for Transmit complete */
2805static irqreturn_t gfar_transmit(int irq, void *grp_id)
2806{
2807 struct gfar_priv_grp *grp = (struct gfar_priv_grp *)grp_id;
2808 unsigned long flags;
2809 u32 imask;
2810
2811 if (likely(napi_schedule_prep(&grp->napi_tx))) {
2812 spin_lock_irqsave(&grp->grplock, flags);
2813 imask = gfar_read(&grp->regs->imask);
2814 imask &= IMASK_TX_DISABLED;
2815 gfar_write(&grp->regs->imask, imask);
2816 spin_unlock_irqrestore(&grp->grplock, flags);
2817 __napi_schedule(&grp->napi_tx);
2818 } else {
2819 /* Clear IEVENT, so interrupts aren't called again
2820 * because of the packets that have already arrived.
2821 */
2822 gfar_write(&grp->regs->ievent, IEVENT_TX_MASK);
2823 }
2824
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 return IRQ_HANDLED;
2826}
2827
Kumar Gala0bbaf062005-06-20 10:54:21 -05002828static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
2829{
2830 /* If valid headers were found, and valid sums
2831 * were verified, then we tell the kernel that no
Jan Ceuleers0977f812012-06-05 03:42:12 +00002832 * checksumming is necessary. Otherwise, it is [FIXME]
2833 */
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002834 if ((be16_to_cpu(fcb->flags) & RXFCB_CSUM_MASK) ==
2835 (RXFCB_CIP | RXFCB_CTU))
Kumar Gala0bbaf062005-06-20 10:54:21 -05002836 skb->ip_summed = CHECKSUM_UNNECESSARY;
2837 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -07002838 skb_checksum_none_assert(skb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002839}
2840
Jan Ceuleers0977f812012-06-05 03:42:12 +00002841/* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */
Claudiu Manoil61db26c2013-02-14 05:00:05 +00002842static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
2843 int amount_pull, struct napi_struct *napi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844{
2845 struct gfar_private *priv = netdev_priv(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002846 struct rxfcb *fcb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Dai Haruki2c2db482008-12-16 15:31:15 -08002848 /* fcb is at the beginning if exists */
2849 fcb = (struct rxfcb *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
Jan Ceuleers0977f812012-06-05 03:42:12 +00002851 /* Remove the FCB from the skb
2852 * Remove the padded bytes, if there are any
2853 */
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002854 if (amount_pull) {
2855 skb_record_rx_queue(skb, fcb->rq);
Dai Haruki2c2db482008-12-16 15:31:15 -08002856 skb_pull(skb, amount_pull);
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002857 }
Kumar Gala0bbaf062005-06-20 10:54:21 -05002858
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00002859 /* Get receive timestamp from the skb */
2860 if (priv->hwts_rx_en) {
2861 struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
2862 u64 *ns = (u64 *) skb->data;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002863
Manfred Rudigiercc772ab2010-04-08 23:10:03 +00002864 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
2865 shhwtstamps->hwtstamp = ns_to_ktime(*ns);
2866 }
2867
2868 if (priv->padding)
2869 skb_pull(skb, priv->padding);
2870
Michał Mirosław8b3afe92011-04-15 04:50:50 +00002871 if (dev->features & NETIF_F_RXCSUM)
Dai Haruki2c2db482008-12-16 15:31:15 -08002872 gfar_rx_checksum(skb, fcb);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002873
Dai Haruki2c2db482008-12-16 15:31:15 -08002874 /* Tell the skb what kind of packet this is */
2875 skb->protocol = eth_type_trans(skb, dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -05002876
Patrick McHardyf6469682013-04-19 02:04:27 +00002877 /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here.
David S. Miller823dcd22011-08-20 10:39:12 -07002878 * Even if vlan rx accel is disabled, on some chips
2879 * RXFCB_VLN is pseudo randomly set.
2880 */
Patrick McHardyf6469682013-04-19 02:04:27 +00002881 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX &&
Claudiu Manoil26eb9372015-03-13 10:36:29 +02002882 be16_to_cpu(fcb->flags) & RXFCB_VLN)
2883 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
2884 be16_to_cpu(fcb->vlctl));
Jiri Pirko87c288c2011-07-20 04:54:19 +00002885
Dai Haruki2c2db482008-12-16 15:31:15 -08002886 /* Send the packet up the stack */
Claudiu Manoil953d2762013-03-21 03:12:15 +00002887 napi_gro_receive(napi, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889}
2890
2891/* gfar_clean_rx_ring() -- Processes each frame in the rx ring
Jan Ceuleers2281a0f2012-06-05 03:42:11 +00002892 * until the budget/quota has been reached. Returns the number
2893 * of frames handled
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002895int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002897 struct net_device *dev = rx_queue->dev;
Andy Fleming31de1982008-12-16 15:33:40 -08002898 struct rxbd8 *bdp, *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 struct sk_buff *skb;
Dai Haruki2c2db482008-12-16 15:31:15 -08002900 int pkt_len;
2901 int amount_pull;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 int howmany = 0;
2903 struct gfar_private *priv = netdev_priv(dev);
2904
2905 /* Get the first full descriptor */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002906 bdp = rx_queue->cur_rx;
2907 base = rx_queue->rx_bd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
Claudiu Manoilba779712013-02-14 05:00:07 +00002909 amount_pull = priv->uses_rxfcb ? GMAC_FCB_LEN : 0;
Dai Haruki2c2db482008-12-16 15:31:15 -08002910
Claudiu Manoila7312d52015-03-13 10:36:28 +02002911 while (!(be16_to_cpu(bdp->status) & RXBD_EMPTY) && rx_work_limit--) {
Andy Fleming815b97c2008-04-22 17:18:29 -05002912 struct sk_buff *newskb;
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002913 dma_addr_t bufaddr;
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002914
Scott Wood3b6330c2007-05-16 15:06:59 -05002915 rmb();
Andy Fleming815b97c2008-04-22 17:18:29 -05002916
2917 /* Add another skb for the future */
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002918 newskb = gfar_new_skb(dev, &bufaddr);
Andy Fleming815b97c2008-04-22 17:18:29 -05002919
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002920 skb = rx_queue->rx_skbuff[rx_queue->skb_currx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
Claudiu Manoila7312d52015-03-13 10:36:28 +02002922 dma_unmap_single(priv->dev, be32_to_cpu(bdp->bufPtr),
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002923 priv->rx_buffer_size, DMA_FROM_DEVICE);
Andy Fleming81183052008-11-12 10:07:11 -06002924
Claudiu Manoila7312d52015-03-13 10:36:28 +02002925 if (unlikely(!(be16_to_cpu(bdp->status) & RXBD_ERR) &&
2926 be16_to_cpu(bdp->length) > priv->rx_buffer_size))
2927 bdp->status = cpu_to_be16(RXBD_LARGE);
Anton Vorontsov63b88b92010-06-11 10:51:03 +00002928
Andy Fleming815b97c2008-04-22 17:18:29 -05002929 /* We drop the frame if we failed to allocate a new buffer */
Claudiu Manoila7312d52015-03-13 10:36:28 +02002930 if (unlikely(!newskb ||
2931 !(be16_to_cpu(bdp->status) & RXBD_LAST) ||
2932 be16_to_cpu(bdp->status) & RXBD_ERR)) {
2933 count_errors(be16_to_cpu(bdp->status), dev);
Andy Fleming815b97c2008-04-22 17:18:29 -05002934
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002935 if (unlikely(!newskb)) {
Andy Fleming815b97c2008-04-22 17:18:29 -05002936 newskb = skb;
Claudiu Manoila7312d52015-03-13 10:36:28 +02002937 bufaddr = be32_to_cpu(bdp->bufPtr);
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002938 } else if (skb)
Eric Dumazetacb600d2012-10-05 06:23:55 +00002939 dev_kfree_skb(skb);
Andy Fleming815b97c2008-04-22 17:18:29 -05002940 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 /* Increment the number of packets */
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002942 rx_queue->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 howmany++;
2944
Dai Haruki2c2db482008-12-16 15:31:15 -08002945 if (likely(skb)) {
Claudiu Manoila7312d52015-03-13 10:36:28 +02002946 pkt_len = be16_to_cpu(bdp->length) -
2947 ETH_FCS_LEN;
Dai Haruki2c2db482008-12-16 15:31:15 -08002948 /* Remove the FCS from the packet length */
2949 skb_put(skb, pkt_len);
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002950 rx_queue->stats.rx_bytes += pkt_len;
Sandeep Gopalpetf74dac02009-12-24 03:13:06 +00002951 skb_record_rx_queue(skb, rx_queue->qindex);
Wu Jiajun-B06378cd754a52012-04-19 22:54:35 +00002952 gfar_process_frame(dev, skb, amount_pull,
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002953 &rx_queue->grp->napi_rx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
Dai Haruki2c2db482008-12-16 15:31:15 -08002955 } else {
Joe Perches59deab22011-06-14 08:57:47 +00002956 netif_warn(priv, rx_err, dev, "Missing skb!\n");
Sandeep Gopalpeta7f38042009-12-16 01:15:07 +00002957 rx_queue->stats.rx_dropped++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05002958 atomic64_inc(&priv->extra_stats.rx_skbmissing);
Dai Haruki2c2db482008-12-16 15:31:15 -08002959 }
2960
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 }
2962
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002963 rx_queue->rx_skbuff[rx_queue->skb_currx] = newskb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Andy Fleming815b97c2008-04-22 17:18:29 -05002965 /* Setup the new bdp */
Kevin Hao0a4b5a22014-12-11 14:08:41 +08002966 gfar_init_rxbdp(rx_queue, bdp, bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Matei Pavaluca45b679c92014-10-27 10:42:44 +02002968 /* Update Last Free RxBD pointer for LFC */
2969 if (unlikely(rx_queue->rfbptr && priv->tx_actual_en))
2970 gfar_write(rx_queue->rfbptr, (u32)bdp);
2971
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 /* Update to the next pointer */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002973 bdp = next_bd(bdp, base, rx_queue->rx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 /* update to point at the next skb */
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00002976 rx_queue->skb_currx = (rx_queue->skb_currx + 1) &
2977 RX_RING_MOD_MASK(rx_queue->rx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 }
2979
2980 /* Update the current rxbd pointer to be the next one */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00002981 rx_queue->cur_rx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return howmany;
2984}
2985
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002986static int gfar_poll_rx_sq(struct napi_struct *napi, int budget)
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002987{
2988 struct gfar_priv_grp *gfargrp =
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002989 container_of(napi, struct gfar_priv_grp, napi_rx);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002990 struct gfar __iomem *regs = gfargrp->regs;
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02002991 struct gfar_priv_rx_q *rx_queue = gfargrp->rx_queue;
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002992 int work_done = 0;
2993
2994 /* Clear IEVENT, so interrupts aren't called again
2995 * because of the packets that have already arrived
2996 */
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02002997 gfar_write(&regs->ievent, IEVENT_RX_MASK);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03002998
2999 work_done = gfar_clean_rx_ring(rx_queue, budget);
3000
3001 if (work_done < budget) {
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003002 u32 imask;
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03003003 napi_complete(napi);
3004 /* Clear the halt bit in RSTAT */
3005 gfar_write(&regs->rstat, gfargrp->rstat);
3006
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003007 spin_lock_irq(&gfargrp->grplock);
3008 imask = gfar_read(&regs->imask);
3009 imask |= IMASK_RX_DEFAULT;
3010 gfar_write(&regs->imask, imask);
3011 spin_unlock_irq(&gfargrp->grplock);
Claudiu Manoil5eaedf32013-06-10 20:19:48 +03003012 }
3013
3014 return work_done;
3015}
3016
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003017static int gfar_poll_tx_sq(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018{
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003019 struct gfar_priv_grp *gfargrp =
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003020 container_of(napi, struct gfar_priv_grp, napi_tx);
3021 struct gfar __iomem *regs = gfargrp->regs;
Claudiu Manoil71ff9e32014-03-07 14:42:46 +02003022 struct gfar_priv_tx_q *tx_queue = gfargrp->tx_queue;
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003023 u32 imask;
3024
3025 /* Clear IEVENT, so interrupts aren't called again
3026 * because of the packets that have already arrived
3027 */
3028 gfar_write(&regs->ievent, IEVENT_TX_MASK);
3029
3030 /* run Tx cleanup to completion */
3031 if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx])
3032 gfar_clean_tx_ring(tx_queue);
3033
3034 napi_complete(napi);
3035
3036 spin_lock_irq(&gfargrp->grplock);
3037 imask = gfar_read(&regs->imask);
3038 imask |= IMASK_TX_DEFAULT;
3039 gfar_write(&regs->imask, imask);
3040 spin_unlock_irq(&gfargrp->grplock);
3041
3042 return 0;
3043}
3044
3045static int gfar_poll_rx(struct napi_struct *napi, int budget)
3046{
3047 struct gfar_priv_grp *gfargrp =
3048 container_of(napi, struct gfar_priv_grp, napi_rx);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003049 struct gfar_private *priv = gfargrp->priv;
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003050 struct gfar __iomem *regs = gfargrp->regs;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003051 struct gfar_priv_rx_q *rx_queue = NULL;
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003052 int work_done = 0, work_done_per_q = 0;
Claudiu Manoil39c0a0d2013-03-21 03:12:13 +00003053 int i, budget_per_q = 0;
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003054 unsigned long rstat_rxf;
3055 int num_act_queues;
Dai Harukid080cd62008-04-09 19:37:51 -05003056
Dai Haruki8c7396a2008-12-17 16:52:00 -08003057 /* Clear IEVENT, so interrupts aren't called again
Jan Ceuleers0977f812012-06-05 03:42:12 +00003058 * because of the packets that have already arrived
3059 */
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003060 gfar_write(&regs->ievent, IEVENT_RX_MASK);
Dai Haruki8c7396a2008-12-17 16:52:00 -08003061
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003062 rstat_rxf = gfar_read(&regs->rstat) & RSTAT_RXF_MASK;
3063
3064 num_act_queues = bitmap_weight(&rstat_rxf, MAX_RX_QS);
3065 if (num_act_queues)
3066 budget_per_q = budget/num_act_queues;
3067
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003068 for_each_set_bit(i, &gfargrp->rx_bit_map, priv->num_rx_queues) {
3069 /* skip queue if not active */
3070 if (!(rstat_rxf & (RSTAT_CLEAR_RXF0 >> i)))
3071 continue;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003072
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003073 rx_queue = priv->rx_queue[i];
3074 work_done_per_q =
3075 gfar_clean_rx_ring(rx_queue, budget_per_q);
3076 work_done += work_done_per_q;
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003077
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003078 /* finished processing this queue */
3079 if (work_done_per_q < budget_per_q) {
3080 /* clear active queue hw indication */
3081 gfar_write(&regs->rstat,
3082 RSTAT_CLEAR_RXF0 >> i);
3083 num_act_queues--;
Claudiu Manoil6be5ed32013-03-19 07:40:03 +00003084
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003085 if (!num_act_queues)
3086 break;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +00003087 }
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003088 }
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003089
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003090 if (!num_act_queues) {
3091 u32 imask;
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003092 napi_complete(napi);
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003093
Claudiu Manoil3ba405d2013-10-14 17:05:09 +03003094 /* Clear the halt bit in RSTAT */
3095 gfar_write(&regs->rstat, gfargrp->rstat);
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003096
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003097 spin_lock_irq(&gfargrp->grplock);
3098 imask = gfar_read(&regs->imask);
3099 imask |= IMASK_RX_DEFAULT;
3100 gfar_write(&regs->imask, imask);
3101 spin_unlock_irq(&gfargrp->grplock);
Dai Harukid080cd62008-04-09 19:37:51 -05003102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
Claudiu Manoilc233cf402013-03-19 07:40:02 +00003104 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106
Claudiu Manoilaeb12c52014-03-07 14:42:45 +02003107static int gfar_poll_tx(struct napi_struct *napi, int budget)
3108{
3109 struct gfar_priv_grp *gfargrp =
3110 container_of(napi, struct gfar_priv_grp, napi_tx);
3111 struct gfar_private *priv = gfargrp->priv;
3112 struct gfar __iomem *regs = gfargrp->regs;
3113 struct gfar_priv_tx_q *tx_queue = NULL;
3114 int has_tx_work = 0;
3115 int i;
3116
3117 /* Clear IEVENT, so interrupts aren't called again
3118 * because of the packets that have already arrived
3119 */
3120 gfar_write(&regs->ievent, IEVENT_TX_MASK);
3121
3122 for_each_set_bit(i, &gfargrp->tx_bit_map, priv->num_tx_queues) {
3123 tx_queue = priv->tx_queue[i];
3124 /* run Tx cleanup to completion */
3125 if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx]) {
3126 gfar_clean_tx_ring(tx_queue);
3127 has_tx_work = 1;
3128 }
3129 }
3130
3131 if (!has_tx_work) {
3132 u32 imask;
3133 napi_complete(napi);
3134
3135 spin_lock_irq(&gfargrp->grplock);
3136 imask = gfar_read(&regs->imask);
3137 imask |= IMASK_TX_DEFAULT;
3138 gfar_write(&regs->imask, imask);
3139 spin_unlock_irq(&gfargrp->grplock);
3140 }
3141
3142 return 0;
3143}
3144
3145
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003146#ifdef CONFIG_NET_POLL_CONTROLLER
Jan Ceuleers0977f812012-06-05 03:42:12 +00003147/* Polling 'interrupt' - used by things like netconsole to send skbs
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003148 * without having to re-enable interrupts. It's not called while
3149 * the interrupt routine is executing.
3150 */
3151static void gfar_netpoll(struct net_device *dev)
3152{
3153 struct gfar_private *priv = netdev_priv(dev);
Jan Ceuleers3a2e16c2012-06-05 03:42:14 +00003154 int i;
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003155
3156 /* If the device has multiple interrupts, run tx/rx */
Andy Flemingb31a1d82008-12-16 15:29:15 -08003157 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003158 for (i = 0; i < priv->num_grps; i++) {
Paul Gortmaker62ed8392013-02-24 05:38:31 +00003159 struct gfar_priv_grp *grp = &priv->gfargrp[i];
3160
3161 disable_irq(gfar_irq(grp, TX)->irq);
3162 disable_irq(gfar_irq(grp, RX)->irq);
3163 disable_irq(gfar_irq(grp, ER)->irq);
3164 gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
3165 enable_irq(gfar_irq(grp, ER)->irq);
3166 enable_irq(gfar_irq(grp, RX)->irq);
3167 enable_irq(gfar_irq(grp, TX)->irq);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003168 }
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003169 } else {
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003170 for (i = 0; i < priv->num_grps; i++) {
Paul Gortmaker62ed8392013-02-24 05:38:31 +00003171 struct gfar_priv_grp *grp = &priv->gfargrp[i];
3172
3173 disable_irq(gfar_irq(grp, TX)->irq);
3174 gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
3175 enable_irq(gfar_irq(grp, TX)->irq);
Anton Vorontsov43de0042009-12-09 02:52:19 -08003176 }
Vitaly Woolf2d71c22006-11-07 13:27:02 +03003177 }
3178}
3179#endif
3180
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181/* The interrupt handler for devices with one interrupt */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003182static irqreturn_t gfar_interrupt(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183{
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003184 struct gfar_priv_grp *gfargrp = grp_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 /* Save ievent for future reference */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003187 u32 events = gfar_read(&gfargrp->regs->ievent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 /* Check for reception */
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003190 if (events & IEVENT_RX_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003191 gfar_receive(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192
3193 /* Check for transmit completion */
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003194 if (events & IEVENT_TX_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003195 gfar_transmit(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Sergei Shtylyov538cc7e2007-02-15 17:56:01 +04003197 /* Check for errors */
3198 if (events & IEVENT_ERR_MASK)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003199 gfar_error(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 return IRQ_HANDLED;
3202}
3203
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204/* Called every time the controller might need to be made
3205 * aware of new link state. The PHY code conveys this
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003206 * information through variables in the phydev structure, and this
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 * function converts those variables into the appropriate
3208 * register values, and can bring down the device if needed.
3209 */
3210static void adjust_link(struct net_device *dev)
3211{
3212 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003213 struct phy_device *phydev = priv->phydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003215 if (unlikely(phydev->link != priv->oldlink ||
Guenter Roeck0ae93b22015-03-02 12:03:27 -08003216 (phydev->link && (phydev->duplex != priv->oldduplex ||
3217 phydev->speed != priv->oldspeed))))
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003218 gfar_update_link_state(priv);
Andy Flemingbb40dcb2005-09-23 22:54:21 -04003219}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221/* Update the hash table based on the current list of multicast
3222 * addresses we subscribe to. Also, change the promiscuity of
3223 * the device based on the flags (this function is called
Jan Ceuleers0977f812012-06-05 03:42:12 +00003224 * whenever dev->flags is changed
3225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226static void gfar_set_multi(struct net_device *dev)
3227{
Jiri Pirko22bedad32010-04-01 21:22:57 +00003228 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003230 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 u32 tempval;
3232
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00003233 if (dev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 /* Set RCTRL to PROM */
3235 tempval = gfar_read(&regs->rctrl);
3236 tempval |= RCTRL_PROM;
3237 gfar_write(&regs->rctrl, tempval);
3238 } else {
3239 /* Set RCTRL to not PROM */
3240 tempval = gfar_read(&regs->rctrl);
3241 tempval &= ~(RCTRL_PROM);
3242 gfar_write(&regs->rctrl, tempval);
3243 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003244
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +00003245 if (dev->flags & IFF_ALLMULTI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 /* Set the hash to rx all multicast frames */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003247 gfar_write(&regs->igaddr0, 0xffffffff);
3248 gfar_write(&regs->igaddr1, 0xffffffff);
3249 gfar_write(&regs->igaddr2, 0xffffffff);
3250 gfar_write(&regs->igaddr3, 0xffffffff);
3251 gfar_write(&regs->igaddr4, 0xffffffff);
3252 gfar_write(&regs->igaddr5, 0xffffffff);
3253 gfar_write(&regs->igaddr6, 0xffffffff);
3254 gfar_write(&regs->igaddr7, 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 gfar_write(&regs->gaddr0, 0xffffffff);
3256 gfar_write(&regs->gaddr1, 0xffffffff);
3257 gfar_write(&regs->gaddr2, 0xffffffff);
3258 gfar_write(&regs->gaddr3, 0xffffffff);
3259 gfar_write(&regs->gaddr4, 0xffffffff);
3260 gfar_write(&regs->gaddr5, 0xffffffff);
3261 gfar_write(&regs->gaddr6, 0xffffffff);
3262 gfar_write(&regs->gaddr7, 0xffffffff);
3263 } else {
Andy Fleming7f7f5312005-11-11 12:38:59 -06003264 int em_num;
3265 int idx;
3266
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 /* zero out the hash */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003268 gfar_write(&regs->igaddr0, 0x0);
3269 gfar_write(&regs->igaddr1, 0x0);
3270 gfar_write(&regs->igaddr2, 0x0);
3271 gfar_write(&regs->igaddr3, 0x0);
3272 gfar_write(&regs->igaddr4, 0x0);
3273 gfar_write(&regs->igaddr5, 0x0);
3274 gfar_write(&regs->igaddr6, 0x0);
3275 gfar_write(&regs->igaddr7, 0x0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 gfar_write(&regs->gaddr0, 0x0);
3277 gfar_write(&regs->gaddr1, 0x0);
3278 gfar_write(&regs->gaddr2, 0x0);
3279 gfar_write(&regs->gaddr3, 0x0);
3280 gfar_write(&regs->gaddr4, 0x0);
3281 gfar_write(&regs->gaddr5, 0x0);
3282 gfar_write(&regs->gaddr6, 0x0);
3283 gfar_write(&regs->gaddr7, 0x0);
3284
Andy Fleming7f7f5312005-11-11 12:38:59 -06003285 /* If we have extended hash tables, we need to
3286 * clear the exact match registers to prepare for
Jan Ceuleers0977f812012-06-05 03:42:12 +00003287 * setting them
3288 */
Andy Fleming7f7f5312005-11-11 12:38:59 -06003289 if (priv->extended_hash) {
3290 em_num = GFAR_EM_NUM + 1;
3291 gfar_clear_exact_match(dev);
3292 idx = 1;
3293 } else {
3294 idx = 0;
3295 em_num = 0;
3296 }
3297
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003298 if (netdev_mc_empty(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 return;
3300
3301 /* Parse the list, and set the appropriate bits */
Jiri Pirko22bedad32010-04-01 21:22:57 +00003302 netdev_for_each_mc_addr(ha, dev) {
Andy Fleming7f7f5312005-11-11 12:38:59 -06003303 if (idx < em_num) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003304 gfar_set_mac_for_addr(dev, idx, ha->addr);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003305 idx++;
3306 } else
Jiri Pirko22bedad32010-04-01 21:22:57 +00003307 gfar_set_hash_for_addr(dev, ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 }
3309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310}
3311
Andy Fleming7f7f5312005-11-11 12:38:59 -06003312
3313/* Clears each of the exact match registers to zero, so they
Jan Ceuleers0977f812012-06-05 03:42:12 +00003314 * don't interfere with normal reception
3315 */
Andy Fleming7f7f5312005-11-11 12:38:59 -06003316static void gfar_clear_exact_match(struct net_device *dev)
3317{
3318 int idx;
Joe Perches6a3c9102011-11-16 09:38:02 +00003319 static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
Andy Fleming7f7f5312005-11-11 12:38:59 -06003320
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003321 for (idx = 1; idx < GFAR_EM_NUM + 1; idx++)
Joe Perchesb6bc7652010-12-21 02:16:08 -08003322 gfar_set_mac_for_addr(dev, idx, zero_arr);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003323}
3324
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325/* Set the appropriate hash bit for the given addr */
3326/* The algorithm works like so:
3327 * 1) Take the Destination Address (ie the multicast address), and
3328 * do a CRC on it (little endian), and reverse the bits of the
3329 * result.
3330 * 2) Use the 8 most significant bits as a hash into a 256-entry
3331 * table. The table is controlled through 8 32-bit registers:
3332 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
3333 * gaddr7. This means that the 3 most significant bits in the
3334 * hash index which gaddr register to use, and the 5 other bits
3335 * indicate which bit (assuming an IBM numbering scheme, which
3336 * for PowerPC (tm) is usually the case) in the register holds
Jan Ceuleers0977f812012-06-05 03:42:12 +00003337 * the entry.
3338 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
3340{
3341 u32 tempval;
3342 struct gfar_private *priv = netdev_priv(dev);
Joe Perches6a3c9102011-11-16 09:38:02 +00003343 u32 result = ether_crc(ETH_ALEN, addr);
Kumar Gala0bbaf062005-06-20 10:54:21 -05003344 int width = priv->hash_width;
3345 u8 whichbit = (result >> (32 - width)) & 0x1f;
3346 u8 whichreg = result >> (32 - width + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 u32 value = (1 << (31-whichbit));
3348
Kumar Gala0bbaf062005-06-20 10:54:21 -05003349 tempval = gfar_read(priv->hash_regs[whichreg]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 tempval |= value;
Kumar Gala0bbaf062005-06-20 10:54:21 -05003351 gfar_write(priv->hash_regs[whichreg], tempval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352}
3353
Andy Fleming7f7f5312005-11-11 12:38:59 -06003354
3355/* There are multiple MAC Address register pairs on some controllers
3356 * This function sets the numth pair to a given address
3357 */
Joe Perchesb6bc7652010-12-21 02:16:08 -08003358static void gfar_set_mac_for_addr(struct net_device *dev, int num,
3359 const u8 *addr)
Andy Fleming7f7f5312005-11-11 12:38:59 -06003360{
3361 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003362 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -06003363 u32 tempval;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003364 u32 __iomem *macptr = &regs->macstnaddr1;
Andy Fleming7f7f5312005-11-11 12:38:59 -06003365
3366 macptr += num*2;
3367
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003368 /* For a station address of 0x12345678ABCD in transmission
3369 * order (BE), MACnADDR1 is set to 0xCDAB7856 and
3370 * MACnADDR2 is set to 0x34120000.
Jan Ceuleers0977f812012-06-05 03:42:12 +00003371 */
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003372 tempval = (addr[5] << 24) | (addr[4] << 16) |
3373 (addr[3] << 8) | addr[2];
Andy Fleming7f7f5312005-11-11 12:38:59 -06003374
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003375 gfar_write(macptr, tempval);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003376
Claudiu Manoil83bfc3c2014-10-07 10:44:33 +03003377 tempval = (addr[1] << 24) | (addr[0] << 16);
Andy Fleming7f7f5312005-11-11 12:38:59 -06003378
3379 gfar_write(macptr+1, tempval);
3380}
3381
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382/* GFAR error interrupt handler */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003383static irqreturn_t gfar_error(int irq, void *grp_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384{
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003385 struct gfar_priv_grp *gfargrp = grp_id;
3386 struct gfar __iomem *regs = gfargrp->regs;
3387 struct gfar_private *priv= gfargrp->priv;
3388 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
3390 /* Save ievent for future reference */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003391 u32 events = gfar_read(&regs->ievent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392
3393 /* Clear IEVENT */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003394 gfar_write(&regs->ievent, events & IEVENT_ERR_MASK);
Scott Woodd87eb122008-07-11 18:04:45 -05003395
3396 /* Magic Packet is not an error. */
Andy Flemingb31a1d82008-12-16 15:29:15 -08003397 if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
Scott Woodd87eb122008-07-11 18:04:45 -05003398 (events & IEVENT_MAG))
3399 events &= ~IEVENT_MAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400
3401 /* Hmm... */
Kumar Gala0bbaf062005-06-20 10:54:21 -05003402 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
Jan Ceuleersbc4598b2012-06-05 03:42:13 +00003403 netdev_dbg(dev,
3404 "error interrupt (ievent=0x%08x imask=0x%08x)\n",
Joe Perches59deab22011-06-14 08:57:47 +00003405 events, gfar_read(&regs->imask));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
3407 /* Update the error counters */
3408 if (events & IEVENT_TXE) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003409 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
3411 if (events & IEVENT_LC)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003412 dev->stats.tx_window_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 if (events & IEVENT_CRL)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003414 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 if (events & IEVENT_XFUN) {
Joe Perches59deab22011-06-14 08:57:47 +00003416 netif_dbg(priv, tx_err, dev,
3417 "TX FIFO underrun, packet dropped\n");
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003418 dev->stats.tx_dropped++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003419 atomic64_inc(&priv->extra_stats.tx_underrun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
Claudiu Manoilbc602282015-05-06 18:07:29 +03003421 schedule_work(&priv->reset_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 }
Joe Perches59deab22011-06-14 08:57:47 +00003423 netif_dbg(priv, tx_err, dev, "Transmit Error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425 if (events & IEVENT_BSY) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003426 dev->stats.rx_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003427 atomic64_inc(&priv->extra_stats.rx_bsy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
Sandeep Gopalpetf4983702009-11-02 07:03:09 +00003429 gfar_receive(irq, grp_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
Joe Perches59deab22011-06-14 08:57:47 +00003431 netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n",
3432 gfar_read(&regs->rstat));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 }
3434 if (events & IEVENT_BABR) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07003435 dev->stats.rx_errors++;
Paul Gortmaker212079d2013-02-12 15:38:19 -05003436 atomic64_inc(&priv->extra_stats.rx_babr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
Joe Perches59deab22011-06-14 08:57:47 +00003438 netif_dbg(priv, rx_err, dev, "babbling RX error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
3440 if (events & IEVENT_EBERR) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05003441 atomic64_inc(&priv->extra_stats.eberr);
Joe Perches59deab22011-06-14 08:57:47 +00003442 netif_dbg(priv, rx_err, dev, "bus error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 }
Joe Perches59deab22011-06-14 08:57:47 +00003444 if (events & IEVENT_RXC)
3445 netif_dbg(priv, rx_status, dev, "control frame\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 if (events & IEVENT_BABT) {
Paul Gortmaker212079d2013-02-12 15:38:19 -05003448 atomic64_inc(&priv->extra_stats.tx_babt);
Joe Perches59deab22011-06-14 08:57:47 +00003449 netif_dbg(priv, tx_err, dev, "babbling TX error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 }
3451 return IRQ_HANDLED;
3452}
3453
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003454static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
3455{
3456 struct phy_device *phydev = priv->phydev;
3457 u32 val = 0;
3458
3459 if (!phydev->duplex)
3460 return val;
3461
3462 if (!priv->pause_aneg_en) {
3463 if (priv->tx_pause_en)
3464 val |= MACCFG1_TX_FLOW;
3465 if (priv->rx_pause_en)
3466 val |= MACCFG1_RX_FLOW;
3467 } else {
3468 u16 lcl_adv, rmt_adv;
3469 u8 flowctrl;
3470 /* get link partner capabilities */
3471 rmt_adv = 0;
3472 if (phydev->pause)
3473 rmt_adv = LPA_PAUSE_CAP;
3474 if (phydev->asym_pause)
3475 rmt_adv |= LPA_PAUSE_ASYM;
3476
Pavaluca Matei-B4661043ef8d22014-10-27 10:42:43 +02003477 lcl_adv = 0;
3478 if (phydev->advertising & ADVERTISED_Pause)
3479 lcl_adv |= ADVERTISE_PAUSE_CAP;
3480 if (phydev->advertising & ADVERTISED_Asym_Pause)
3481 lcl_adv |= ADVERTISE_PAUSE_ASYM;
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003482
3483 flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
3484 if (flowctrl & FLOW_CTRL_TX)
3485 val |= MACCFG1_TX_FLOW;
3486 if (flowctrl & FLOW_CTRL_RX)
3487 val |= MACCFG1_RX_FLOW;
3488 }
3489
3490 return val;
3491}
3492
3493static noinline void gfar_update_link_state(struct gfar_private *priv)
3494{
3495 struct gfar __iomem *regs = priv->gfargrp[0].regs;
3496 struct phy_device *phydev = priv->phydev;
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003497 struct gfar_priv_rx_q *rx_queue = NULL;
3498 int i;
3499 struct rxbd8 *bdp;
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003500
3501 if (unlikely(test_bit(GFAR_RESETTING, &priv->state)))
3502 return;
3503
3504 if (phydev->link) {
3505 u32 tempval1 = gfar_read(&regs->maccfg1);
3506 u32 tempval = gfar_read(&regs->maccfg2);
3507 u32 ecntrl = gfar_read(&regs->ecntrl);
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003508 u32 tx_flow_oldval = (tempval & MACCFG1_TX_FLOW);
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003509
3510 if (phydev->duplex != priv->oldduplex) {
3511 if (!(phydev->duplex))
3512 tempval &= ~(MACCFG2_FULL_DUPLEX);
3513 else
3514 tempval |= MACCFG2_FULL_DUPLEX;
3515
3516 priv->oldduplex = phydev->duplex;
3517 }
3518
3519 if (phydev->speed != priv->oldspeed) {
3520 switch (phydev->speed) {
3521 case 1000:
3522 tempval =
3523 ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
3524
3525 ecntrl &= ~(ECNTRL_R100);
3526 break;
3527 case 100:
3528 case 10:
3529 tempval =
3530 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
3531
3532 /* Reduced mode distinguishes
3533 * between 10 and 100
3534 */
3535 if (phydev->speed == SPEED_100)
3536 ecntrl |= ECNTRL_R100;
3537 else
3538 ecntrl &= ~(ECNTRL_R100);
3539 break;
3540 default:
3541 netif_warn(priv, link, priv->ndev,
3542 "Ack! Speed (%d) is not 10/100/1000!\n",
3543 phydev->speed);
3544 break;
3545 }
3546
3547 priv->oldspeed = phydev->speed;
3548 }
3549
3550 tempval1 &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
3551 tempval1 |= gfar_get_flowctrl_cfg(priv);
3552
Matei Pavaluca45b679c92014-10-27 10:42:44 +02003553 /* Turn last free buffer recording on */
3554 if ((tempval1 & MACCFG1_TX_FLOW) && !tx_flow_oldval) {
3555 for (i = 0; i < priv->num_rx_queues; i++) {
3556 rx_queue = priv->rx_queue[i];
3557 bdp = rx_queue->cur_rx;
3558 /* skip to previous bd */
3559 bdp = skip_bd(bdp, rx_queue->rx_ring_size - 1,
3560 rx_queue->rx_bd_base,
3561 rx_queue->rx_ring_size);
3562
3563 if (rx_queue->rfbptr)
3564 gfar_write(rx_queue->rfbptr, (u32)bdp);
3565 }
3566
3567 priv->tx_actual_en = 1;
3568 }
3569
3570 if (unlikely(!(tempval1 & MACCFG1_TX_FLOW) && tx_flow_oldval))
3571 priv->tx_actual_en = 0;
3572
Claudiu Manoil6ce29b02014-04-30 14:27:21 +03003573 gfar_write(&regs->maccfg1, tempval1);
3574 gfar_write(&regs->maccfg2, tempval);
3575 gfar_write(&regs->ecntrl, ecntrl);
3576
3577 if (!priv->oldlink)
3578 priv->oldlink = 1;
3579
3580 } else if (priv->oldlink) {
3581 priv->oldlink = 0;
3582 priv->oldspeed = 0;
3583 priv->oldduplex = -1;
3584 }
3585
3586 if (netif_msg_link(priv))
3587 phy_print_status(phydev);
3588}
3589
Fabian Frederick94e5a2a2015-03-17 19:37:34 +01003590static const struct of_device_id gfar_match[] =
Andy Flemingb31a1d82008-12-16 15:29:15 -08003591{
3592 {
3593 .type = "network",
3594 .compatible = "gianfar",
3595 },
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +00003596 {
3597 .compatible = "fsl,etsec2",
3598 },
Andy Flemingb31a1d82008-12-16 15:29:15 -08003599 {},
3600};
Anton Vorontsove72701a2009-10-14 14:54:52 -07003601MODULE_DEVICE_TABLE(of, gfar_match);
Andy Flemingb31a1d82008-12-16 15:29:15 -08003602
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603/* Structure for a device driver */
Grant Likely74888762011-02-22 21:05:51 -07003604static struct platform_driver gfar_driver = {
Grant Likely40182942010-04-13 16:13:02 -07003605 .driver = {
3606 .name = "fsl-gianfar",
Grant Likely40182942010-04-13 16:13:02 -07003607 .pm = GFAR_PM_OPS,
3608 .of_match_table = gfar_match,
3609 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 .probe = gfar_probe,
3611 .remove = gfar_remove,
3612};
3613
Axel Lindb62f682011-11-27 16:44:17 +00003614module_platform_driver(gfar_driver);