blob: f0f0e96453a09129f65109caca0d0cfd3f146a4d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
4 *
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10005 * Right now, I am very wasteful with the buffers. I allocate memory
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * pages and then divide them into 2K frame buffers. This way I know I
7 * have buffers large enough to hold one frame within one buffer descriptor.
8 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
9 * will be much more memory efficient and will easily handle lots of
10 * small packets.
11 *
12 * Much better multiple PHY support by Magnus Damm.
13 * Copyright (c) 2000 Ericsson Radio Systems AB.
14 *
Greg Ungerer562d2f82005-11-07 14:09:50 +100015 * Support for FEC controller of ColdFire processors.
16 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100017 *
18 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
Philippe De Muyter677177c2006-06-27 13:05:33 +100019 * Copyright (c) 2004-2006 Macq Electronique SA.
Shawn Guob5680e02011-01-05 21:13:13 +000020 *
Shawn Guo230dec62011-09-23 02:12:48 +000021 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/string.h>
27#include <linux/ptrace.h>
28#include <linux/errno.h>
29#include <linux/ioport.h>
30#include <linux/slab.h>
31#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/delay.h>
34#include <linux/netdevice.h>
35#include <linux/etherdevice.h>
36#include <linux/skbuff.h>
Jim Baxter4c09eed2013-04-19 08:10:49 +000037#include <linux/in.h>
38#include <linux/ip.h>
39#include <net/ip.h>
40#include <linux/tcp.h>
41#include <linux/udp.h>
42#include <linux/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/spinlock.h>
44#include <linux/workqueue.h>
45#include <linux/bitops.h>
Sascha Hauer6f501b12009-01-28 23:03:05 +000046#include <linux/io.h>
47#include <linux/irq.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000048#include <linux/clk.h>
Sascha Haueread73182009-01-28 23:03:11 +000049#include <linux/platform_device.h>
Bryan Wue6b043d2010-03-31 02:10:44 +000050#include <linux/phy.h>
Baruch Siach5eb32bd2010-05-24 00:36:13 -070051#include <linux/fec.h>
Shawn Guoca2cc332011-06-25 02:04:35 +080052#include <linux/of.h>
53#include <linux/of_device.h>
54#include <linux/of_gpio.h>
55#include <linux/of_net.h>
Shawn Guo5fa9c0f2012-06-27 03:45:21 +000056#include <linux/regulator/consumer.h>
Jim Baxtercdffcf12013-07-02 22:52:56 +010057#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Greg Ungerer080853a2007-07-30 16:28:46 +100059#include <asm/cacheflush.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include "fec.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Christoph Müllner772e42b2013-06-27 21:18:23 +020063static void set_multicast_list(struct net_device *ndev);
64
Uwe Kleine-König085e79e2011-01-17 09:52:18 +010065#if defined(CONFIG_ARM)
Sascha Hauer196719e2009-01-28 23:03:10 +000066#define FEC_ALIGNMENT 0xf
67#else
68#define FEC_ALIGNMENT 0x3
69#endif
70
Shawn Guob5680e02011-01-05 21:13:13 +000071#define DRIVER_NAME "fec"
Frank Lidc975382013-01-28 18:31:42 +000072#define FEC_NAPI_WEIGHT 64
Shawn Guob5680e02011-01-05 21:13:13 +000073
Frank Libaa70a52013-01-16 16:55:58 +000074/* Pause frame feild and FIFO threshold */
75#define FEC_ENET_FCE (1 << 5)
76#define FEC_ENET_RSEM_V 0x84
77#define FEC_ENET_RSFL_V 16
78#define FEC_ENET_RAEM_V 0x8
79#define FEC_ENET_RAFL_V 0x8
80#define FEC_ENET_OPD_V 0xFFF0
81
Shawn Guob5680e02011-01-05 21:13:13 +000082/* Controller is ENET-MAC */
83#define FEC_QUIRK_ENET_MAC (1 << 0)
84/* Controller needs driver to swap frame */
85#define FEC_QUIRK_SWAP_FRAME (1 << 1)
Shawn Guo0ca1e292011-07-01 18:11:22 +080086/* Controller uses gasket */
87#define FEC_QUIRK_USE_GASKET (1 << 2)
Shawn Guo230dec62011-09-23 02:12:48 +000088/* Controller has GBIT support */
89#define FEC_QUIRK_HAS_GBIT (1 << 3)
Frank Liff43da82013-01-03 16:04:23 +000090/* Controller has extend desc buffer */
91#define FEC_QUIRK_HAS_BUFDESC_EX (1 << 4)
Shawn Guo48496252013-05-08 21:08:22 +000092/* Controller has hardware checksum support */
93#define FEC_QUIRK_HAS_CSUM (1 << 5)
Jim Baxtercdffcf12013-07-02 22:52:56 +010094/* Controller has hardware vlan support */
95#define FEC_QUIRK_HAS_VLAN (1 << 6)
Shawn Guob5680e02011-01-05 21:13:13 +000096
97static struct platform_device_id fec_devtype[] = {
98 {
Shawn Guo0ca1e292011-07-01 18:11:22 +080099 /* keep it for coldfire */
Shawn Guob5680e02011-01-05 21:13:13 +0000100 .name = DRIVER_NAME,
101 .driver_data = 0,
102 }, {
Shawn Guo0ca1e292011-07-01 18:11:22 +0800103 .name = "imx25-fec",
104 .driver_data = FEC_QUIRK_USE_GASKET,
105 }, {
106 .name = "imx27-fec",
107 .driver_data = 0,
108 }, {
Shawn Guob5680e02011-01-05 21:13:13 +0000109 .name = "imx28-fec",
110 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
Shawn Guo0ca1e292011-07-01 18:11:22 +0800111 }, {
Shawn Guo230dec62011-09-23 02:12:48 +0000112 .name = "imx6q-fec",
Frank Liff43da82013-01-03 16:04:23 +0000113 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
Jim Baxtercdffcf12013-07-02 22:52:56 +0100114 FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM |
115 FEC_QUIRK_HAS_VLAN,
Shawn Guo230dec62011-09-23 02:12:48 +0000116 }, {
Shawn Guo36803542013-05-19 04:38:46 +0000117 .name = "mvf600-fec",
Jingchang Luca7c4a42013-04-11 21:12:45 +0000118 .driver_data = FEC_QUIRK_ENET_MAC,
119 }, {
Shawn Guo0ca1e292011-07-01 18:11:22 +0800120 /* sentinel */
121 }
Shawn Guob5680e02011-01-05 21:13:13 +0000122};
Shawn Guo0ca1e292011-07-01 18:11:22 +0800123MODULE_DEVICE_TABLE(platform, fec_devtype);
Shawn Guob5680e02011-01-05 21:13:13 +0000124
Shawn Guoca2cc332011-06-25 02:04:35 +0800125enum imx_fec_type {
Lothar Waßmanna7dd3212011-12-07 21:59:25 +0000126 IMX25_FEC = 1, /* runs on i.mx25/50/53 */
Shawn Guoca2cc332011-06-25 02:04:35 +0800127 IMX27_FEC, /* runs on i.mx27/35/51 */
128 IMX28_FEC,
Shawn Guo230dec62011-09-23 02:12:48 +0000129 IMX6Q_FEC,
Shawn Guo36803542013-05-19 04:38:46 +0000130 MVF600_FEC,
Shawn Guoca2cc332011-06-25 02:04:35 +0800131};
132
133static const struct of_device_id fec_dt_ids[] = {
134 { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
135 { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
136 { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
Shawn Guo230dec62011-09-23 02:12:48 +0000137 { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
Shawn Guo36803542013-05-19 04:38:46 +0000138 { .compatible = "fsl,mvf600-fec", .data = &fec_devtype[MVF600_FEC], },
Shawn Guoca2cc332011-06-25 02:04:35 +0800139 { /* sentinel */ }
140};
141MODULE_DEVICE_TABLE(of, fec_dt_ids);
142
Shawn Guo49da97d2011-01-05 21:13:11 +0000143static unsigned char macaddr[ETH_ALEN];
144module_param_array(macaddr, byte, NULL, 0);
145MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
146
Greg Ungerer87f4abb2008-06-06 15:55:36 +1000147#if defined(CONFIG_M5272)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/*
149 * Some hardware gets it MAC address out of local flash memory.
150 * if this is non-zero then assume it is the address to get MAC from.
151 */
152#if defined(CONFIG_NETtel)
153#define FEC_FLASHMAC 0xf0006006
154#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
155#define FEC_FLASHMAC 0xf0006000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#elif defined(CONFIG_CANCam)
157#define FEC_FLASHMAC 0xf0020000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000158#elif defined (CONFIG_M5272C3)
159#define FEC_FLASHMAC (0xffe04000 + 4)
160#elif defined(CONFIG_MOD5272)
Lothar Waßmanna7dd3212011-12-07 21:59:25 +0000161#define FEC_FLASHMAC 0xffc0406b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#else
163#define FEC_FLASHMAC 0
164#endif
Greg Ungerer43be6362009-02-26 22:42:51 -0800165#endif /* CONFIG_M5272 */
Sascha Haueread73182009-01-28 23:03:11 +0000166
Frank Liff43da82013-01-03 16:04:23 +0000167#if (((RX_RING_SIZE + TX_RING_SIZE) * 32) > PAGE_SIZE)
Matt Waddel6b265292006-06-27 13:10:56 +1000168#error "FEC: descriptor ring size constants too large"
Greg Ungerer562d2f82005-11-07 14:09:50 +1000169#endif
170
Sascha Hauer22f6b862009-04-15 01:32:18 +0000171/* Interrupt events/masks. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
173#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
174#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
175#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
176#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
177#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
178#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
179#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
180#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
181#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
182
Wolfram Sang4bee1f92010-07-21 02:51:13 +0000183#define FEC_DEFAULT_IMASK (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII)
Frank Lidc975382013-01-28 18:31:42 +0000184#define FEC_RX_DISABLED_IMASK (FEC_DEFAULT_IMASK & (~FEC_ENET_RXF))
Wolfram Sang4bee1f92010-07-21 02:51:13 +0000185
Jim Baxtercdffcf12013-07-02 22:52:56 +0100186/* The FEC stores dest/src/type/vlan, data, and checksum for receive packets.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 */
Jim Baxtercdffcf12013-07-02 22:52:56 +0100188#define PKT_MAXBUF_SIZE 1522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#define PKT_MINBUF_SIZE 64
Jim Baxtercdffcf12013-07-02 22:52:56 +0100190#define PKT_MAXBLR_SIZE 1536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Jim Baxter4c09eed2013-04-19 08:10:49 +0000192/* FEC receive acceleration */
193#define FEC_RACC_IPDIS (1 << 1)
194#define FEC_RACC_PRODIS (1 << 2)
195#define FEC_RACC_OPTIONS (FEC_RACC_IPDIS | FEC_RACC_PRODIS)
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/*
Matt Waddel6b265292006-06-27 13:10:56 +1000198 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 * size bits. Other FEC hardware does not, so we need to take that into
200 * account when setting it.
201 */
Greg Ungerer562d2f82005-11-07 14:09:50 +1000202#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
Uwe Kleine-König085e79e2011-01-17 09:52:18 +0100203 defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
205#else
206#define OPT_FRAME_SIZE 0
207#endif
208
Bryan Wue6b043d2010-03-31 02:10:44 +0000209/* FEC MII MMFR bits definition */
210#define FEC_MMFR_ST (1 << 30)
211#define FEC_MMFR_OP_READ (2 << 28)
212#define FEC_MMFR_OP_WRITE (1 << 28)
213#define FEC_MMFR_PA(v) ((v & 0x1f) << 23)
214#define FEC_MMFR_RA(v) ((v & 0x1f) << 18)
215#define FEC_MMFR_TA (2 << 16)
216#define FEC_MMFR_DATA(v) (v & 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Rogerio Pimentelc3b084c2011-12-27 14:07:37 -0500218#define FEC_MII_TIMEOUT 30000 /* us */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Sascha Hauer22f6b862009-04-15 01:32:18 +0000220/* Transmitter timeout */
221#define TX_TIMEOUT (2 * HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Frank Libaa70a52013-01-16 16:55:58 +0000223#define FEC_PAUSE_FLAG_AUTONEG 0x1
224#define FEC_PAUSE_FLAG_ENABLE 0x2
225
Lothar Waßmanne163cc92011-12-07 21:59:31 +0000226static int mii_cnt;
227
Frank Liff43da82013-01-03 16:04:23 +0000228static struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp, int is_ex)
229{
230 struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
231 if (is_ex)
232 return (struct bufdesc *)(ex + 1);
233 else
234 return bdp + 1;
235}
236
237static struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp, int is_ex)
238{
239 struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
240 if (is_ex)
241 return (struct bufdesc *)(ex - 1);
242 else
243 return bdp - 1;
244}
245
Shawn Guob5680e02011-01-05 21:13:13 +0000246static void *swap_buffer(void *bufaddr, int len)
247{
248 int i;
249 unsigned int *buf = bufaddr;
250
Fabio Estevamffed61e2013-05-21 05:44:26 +0000251 for (i = 0; i < DIV_ROUND_UP(len, 4); i++, buf++)
Shawn Guob5680e02011-01-05 21:13:13 +0000252 *buf = cpu_to_be32(*buf);
253
254 return bufaddr;
255}
256
Jim Baxter4c09eed2013-04-19 08:10:49 +0000257static int
258fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)
259{
260 /* Only run for packets requiring a checksum. */
261 if (skb->ip_summed != CHECKSUM_PARTIAL)
262 return 0;
263
264 if (unlikely(skb_cow_head(skb, 0)))
265 return -1;
266
267 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
268
269 return 0;
270}
271
Denis Kirjanovc7621cb2010-06-02 09:15:47 +0000272static netdev_tx_t
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100273fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100275 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guob5680e02011-01-05 21:13:13 +0000276 const struct platform_device_id *id_entry =
277 platform_get_device_id(fep->pdev);
Sascha Hauer2e285322009-04-15 01:32:16 +0000278 struct bufdesc *bdp;
Greg Ungerer9555b312009-08-06 17:58:18 +0000279 void *bufaddr;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000280 unsigned short status;
Frank Lide5fb0a2013-03-03 17:34:25 +0000281 unsigned int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (!fep->link) {
Jim Baxter4c09eed2013-04-19 08:10:49 +0000284 /* Link is down or auto-negotiation is in progress. */
Patrick McHardy5b548142009-06-12 06:22:29 +0000285 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
287
288 /* Fill in a Tx ring entry */
289 bdp = fep->cur_tx;
290
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000291 status = bdp->cbd_sc;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000292
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000293 if (status & BD_ENET_TX_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 /* Ooops. All transmit buffers are full. Bail out.
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100295 * This should not happen, since ndev->tbusy should be set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 */
Joe Perches31b77202013-04-13 19:03:17 +0000297 netdev_err(ndev, "tx queue full!\n");
Patrick McHardy5b548142009-06-12 06:22:29 +0000298 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Jim Baxter4c09eed2013-04-19 08:10:49 +0000301 /* Protocol checksum off-load for TCP and UDP. */
302 if (fec_enet_clear_csum(skb, ndev)) {
303 kfree_skb(skb);
304 return NETDEV_TX_OK;
305 }
306
Sascha Hauer22f6b862009-04-15 01:32:18 +0000307 /* Clear all of the status flags */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000308 status &= ~BD_ENET_TX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Sascha Hauer22f6b862009-04-15 01:32:18 +0000310 /* Set buffer length and buffer pointer */
Greg Ungerer9555b312009-08-06 17:58:18 +0000311 bufaddr = skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 bdp->cbd_datlen = skb->len;
313
314 /*
Sascha Hauer22f6b862009-04-15 01:32:18 +0000315 * On some FEC implementations data must be aligned on
316 * 4-byte boundaries. Use bounce buffers to copy data
317 * and get it aligned. Ugh.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 */
Frank Lide5fb0a2013-03-03 17:34:25 +0000319 if (fep->bufdesc_ex)
320 index = (struct bufdesc_ex *)bdp -
321 (struct bufdesc_ex *)fep->tx_bd_base;
322 else
323 index = bdp - fep->tx_bd_base;
324
Greg Ungerer9555b312009-08-06 17:58:18 +0000325 if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
Uwe Kleine-König8a73b0b2011-01-13 21:34:31 +0100326 memcpy(fep->tx_bounce[index], skb->data, skb->len);
Greg Ungerer9555b312009-08-06 17:58:18 +0000327 bufaddr = fep->tx_bounce[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
329
Shawn Guob5680e02011-01-05 21:13:13 +0000330 /*
331 * Some design made an incorrect assumption on endian mode of
332 * the system that it's running on. As the result, driver has to
333 * swap every frame going to and coming from the controller.
334 */
335 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
336 swap_buffer(bufaddr, skb->len);
337
Sascha Hauer22f6b862009-04-15 01:32:18 +0000338 /* Save skb pointer */
Frank Lide5fb0a2013-03-03 17:34:25 +0000339 fep->tx_skbuff[index] = skb;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 /* Push the data cache so the CPM does not get stale memory
342 * data.
343 */
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +0100344 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +0000345 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000347 /* Send it on its way. Tell FEC it's ready, interrupt when done,
348 * it's the last BD of the frame, and to put the CRC on the end.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000350 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000352 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Frank Liff43da82013-01-03 16:04:23 +0000354 if (fep->bufdesc_ex) {
Frank Li6605b732012-10-30 18:25:31 +0000355
Frank Liff43da82013-01-03 16:04:23 +0000356 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
357 ebdp->cbd_bdu = 0;
358 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
359 fep->hwts_tx_en)) {
360 ebdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT);
361 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
362 } else {
Frank Liff43da82013-01-03 16:04:23 +0000363 ebdp->cbd_esc = BD_ENET_TX_INT;
Jim Baxter4c09eed2013-04-19 08:10:49 +0000364
365 /* Enable protocol checksum flags
366 * We do not bother with the IP Checksum bits as they
367 * are done by the kernel
368 */
369 if (skb->ip_summed == CHECKSUM_PARTIAL)
370 ebdp->cbd_esc |= BD_ENET_TX_PINS;
Frank Liff43da82013-01-03 16:04:23 +0000371 }
Frank Li6605b732012-10-30 18:25:31 +0000372 }
Sascha Hauer22f6b862009-04-15 01:32:18 +0000373 /* If this was the last BD in the ring, start at the beginning again. */
374 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 bdp = fep->tx_bd_base;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000376 else
Frank Liff43da82013-01-03 16:04:23 +0000377 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Sascha Hauer2e285322009-04-15 01:32:16 +0000379 fep->cur_tx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Frank Lide5fb0a2013-03-03 17:34:25 +0000381 if (fep->cur_tx == fep->dirty_tx)
382 netif_stop_queue(ndev);
Richard Cochran18a03b92011-06-12 02:18:59 +0000383
Frank Lide5fb0a2013-03-03 17:34:25 +0000384 /* Trigger transmission start */
385 writel(0, fep->hwp + FEC_X_DES_ACTIVE);
386
387 skb_tx_timestamp(skb);
Richard Cochrana0087a32011-06-19 03:31:40 +0000388
Patrick McHardy6ed10652009-06-23 06:03:08 +0000389 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
Frank Li14109a52013-03-26 16:12:03 +0000392/* Init RX & TX buffer descriptors
393 */
394static void fec_enet_bd_init(struct net_device *dev)
395{
396 struct fec_enet_private *fep = netdev_priv(dev);
397 struct bufdesc *bdp;
398 unsigned int i;
399
400 /* Initialize the receive buffer descriptors. */
401 bdp = fep->rx_bd_base;
402 for (i = 0; i < RX_RING_SIZE; i++) {
403
404 /* Initialize the BD for every fragment in the page. */
405 if (bdp->cbd_bufaddr)
406 bdp->cbd_sc = BD_ENET_RX_EMPTY;
407 else
408 bdp->cbd_sc = 0;
409 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
410 }
411
412 /* Set the last buffer to wrap */
413 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
414 bdp->cbd_sc |= BD_SC_WRAP;
415
416 fep->cur_rx = fep->rx_bd_base;
417
418 /* ...and the same for transmit */
419 bdp = fep->tx_bd_base;
420 fep->cur_tx = bdp;
421 for (i = 0; i < TX_RING_SIZE; i++) {
422
423 /* Initialize the BD for every fragment in the page. */
424 bdp->cbd_sc = 0;
425 if (bdp->cbd_bufaddr && fep->tx_skbuff[i]) {
426 dev_kfree_skb_any(fep->tx_skbuff[i]);
427 fep->tx_skbuff[i] = NULL;
428 }
429 bdp->cbd_bufaddr = 0;
430 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
431 }
432
433 /* Set the last buffer to wrap */
434 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
435 bdp->cbd_sc |= BD_SC_WRAP;
436 fep->dirty_tx = bdp;
437}
438
Uwe Kleine-König45993652011-01-19 20:47:04 +0100439/* This function is called to start or restart the FEC during a link
440 * change. This only happens when switching between half and full
441 * duplex.
442 */
443static void
444fec_restart(struct net_device *ndev, int duplex)
445{
446 struct fec_enet_private *fep = netdev_priv(ndev);
447 const struct platform_device_id *id_entry =
448 platform_get_device_id(fep->pdev);
449 int i;
Jim Baxter4c09eed2013-04-19 08:10:49 +0000450 u32 val;
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100451 u32 temp_mac[2];
452 u32 rcntl = OPT_FRAME_SIZE | 0x04;
Shawn Guo230dec62011-09-23 02:12:48 +0000453 u32 ecntl = 0x2; /* ETHEREN */
Uwe Kleine-König45993652011-01-19 20:47:04 +0100454
Frank Li54309fa2013-05-07 14:08:44 +0000455 if (netif_running(ndev)) {
456 netif_device_detach(ndev);
457 napi_disable(&fep->napi);
458 netif_stop_queue(ndev);
Fabio Estevam31691342013-05-15 07:06:26 +0000459 netif_tx_lock_bh(ndev);
Frank Li54309fa2013-05-07 14:08:44 +0000460 }
461
Uwe Kleine-König45993652011-01-19 20:47:04 +0100462 /* Whack a reset. We should wait for this. */
463 writel(1, fep->hwp + FEC_ECNTRL);
464 udelay(10);
465
466 /*
467 * enet-mac reset will reset mac address registers too,
468 * so need to reconfigure it.
469 */
470 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
471 memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
472 writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
473 writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
474 }
475
476 /* Clear any outstanding interrupt. */
477 writel(0xffc00000, fep->hwp + FEC_IEVENT);
478
Christoph Müllner772e42b2013-06-27 21:18:23 +0200479 /* Setup multicast filter. */
480 set_multicast_list(ndev);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100481#ifndef CONFIG_M5272
482 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
483 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
484#endif
485
486 /* Set maximum receive buffer size. */
487 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
488
Frank Li14109a52013-03-26 16:12:03 +0000489 fec_enet_bd_init(ndev);
490
Uwe Kleine-König45993652011-01-19 20:47:04 +0100491 /* Set receive and transmit descriptor base. */
492 writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
Frank Liff43da82013-01-03 16:04:23 +0000493 if (fep->bufdesc_ex)
494 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc_ex)
495 * RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
496 else
497 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc)
498 * RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100499
Uwe Kleine-König45993652011-01-19 20:47:04 +0100500
Uwe Kleine-König45993652011-01-19 20:47:04 +0100501 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
502 if (fep->tx_skbuff[i]) {
503 dev_kfree_skb_any(fep->tx_skbuff[i]);
504 fep->tx_skbuff[i] = NULL;
505 }
506 }
507
508 /* Enable MII mode */
509 if (duplex) {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100510 /* FD enable */
Uwe Kleine-König45993652011-01-19 20:47:04 +0100511 writel(0x04, fep->hwp + FEC_X_CNTRL);
512 } else {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100513 /* No Rcv on Xmit */
514 rcntl |= 0x02;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100515 writel(0x0, fep->hwp + FEC_X_CNTRL);
516 }
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100517
Uwe Kleine-König45993652011-01-19 20:47:04 +0100518 fep->full_duplex = duplex;
519
520 /* Set MII speed */
521 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
522
Guenter Roeckd1391932013-06-18 10:04:59 -0700523#if !defined(CONFIG_M5272)
Jim Baxter4c09eed2013-04-19 08:10:49 +0000524 /* set RX checksum */
525 val = readl(fep->hwp + FEC_RACC);
526 if (fep->csum_flags & FLAG_RX_CSUM_ENABLED)
527 val |= FEC_RACC_OPTIONS;
528 else
529 val &= ~FEC_RACC_OPTIONS;
530 writel(val, fep->hwp + FEC_RACC);
Guenter Roeckd1391932013-06-18 10:04:59 -0700531#endif
Jim Baxter4c09eed2013-04-19 08:10:49 +0000532
Uwe Kleine-König45993652011-01-19 20:47:04 +0100533 /*
534 * The phy interface and speed need to get configured
535 * differently on enet-mac.
536 */
537 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100538 /* Enable flow control and length check */
539 rcntl |= 0x40000000 | 0x00000020;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100540
Shawn Guo230dec62011-09-23 02:12:48 +0000541 /* RGMII, RMII or MII */
542 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII)
543 rcntl |= (1 << 6);
544 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100545 rcntl |= (1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100546 else
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100547 rcntl &= ~(1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100548
Shawn Guo230dec62011-09-23 02:12:48 +0000549 /* 1G, 100M or 10M */
550 if (fep->phy_dev) {
551 if (fep->phy_dev->speed == SPEED_1000)
552 ecntl |= (1 << 5);
553 else if (fep->phy_dev->speed == SPEED_100)
554 rcntl &= ~(1 << 9);
555 else
556 rcntl |= (1 << 9);
557 }
Uwe Kleine-König45993652011-01-19 20:47:04 +0100558 } else {
559#ifdef FEC_MIIGSK_ENR
Shawn Guo0ca1e292011-07-01 18:11:22 +0800560 if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
Eric Benard8d82f212012-01-12 06:10:28 +0000561 u32 cfgr;
Uwe Kleine-König45993652011-01-19 20:47:04 +0100562 /* disable the gasket and wait */
563 writel(0, fep->hwp + FEC_MIIGSK_ENR);
564 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
565 udelay(1);
566
567 /*
568 * configure the gasket:
569 * RMII, 50 MHz, no loopback, no echo
Shawn Guo0ca1e292011-07-01 18:11:22 +0800570 * MII, 25 MHz, no loopback, no echo
Uwe Kleine-König45993652011-01-19 20:47:04 +0100571 */
Eric Benard8d82f212012-01-12 06:10:28 +0000572 cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
573 ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
574 if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
575 cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
576 writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100577
578 /* re-enable the gasket */
579 writel(2, fep->hwp + FEC_MIIGSK_ENR);
580 }
581#endif
582 }
Frank Libaa70a52013-01-16 16:55:58 +0000583
Guenter Roeckd1391932013-06-18 10:04:59 -0700584#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +0000585 /* enable pause frame*/
586 if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) ||
587 ((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) &&
588 fep->phy_dev && fep->phy_dev->pause)) {
589 rcntl |= FEC_ENET_FCE;
590
Jim Baxter4c09eed2013-04-19 08:10:49 +0000591 /* set FIFO threshold parameter to reduce overrun */
Frank Libaa70a52013-01-16 16:55:58 +0000592 writel(FEC_ENET_RSEM_V, fep->hwp + FEC_R_FIFO_RSEM);
593 writel(FEC_ENET_RSFL_V, fep->hwp + FEC_R_FIFO_RSFL);
594 writel(FEC_ENET_RAEM_V, fep->hwp + FEC_R_FIFO_RAEM);
595 writel(FEC_ENET_RAFL_V, fep->hwp + FEC_R_FIFO_RAFL);
596
597 /* OPD */
598 writel(FEC_ENET_OPD_V, fep->hwp + FEC_OPD);
599 } else {
600 rcntl &= ~FEC_ENET_FCE;
601 }
Guenter Roeckd1391932013-06-18 10:04:59 -0700602#endif /* !defined(CONFIG_M5272) */
Frank Libaa70a52013-01-16 16:55:58 +0000603
Uwe Kleine-Königcd1f4022011-01-25 22:11:25 +0100604 writel(rcntl, fep->hwp + FEC_R_CNTRL);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100605
Shawn Guo230dec62011-09-23 02:12:48 +0000606 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
607 /* enable ENET endian swap */
608 ecntl |= (1 << 8);
609 /* enable ENET store and forward mode */
610 writel(1 << 8, fep->hwp + FEC_X_WMRK);
611 }
612
Frank Liff43da82013-01-03 16:04:23 +0000613 if (fep->bufdesc_ex)
614 ecntl |= (1 << 4);
Frank Li6605b732012-10-30 18:25:31 +0000615
Chris Healy38ae92d2013-06-25 23:18:52 -0700616#ifndef CONFIG_M5272
Jim Baxterb9eef552013-07-01 14:57:54 +0100617 /* Enable the MIB statistic event counters */
618 writel(0 << 31, fep->hwp + FEC_MIB_CTRLSTAT);
Chris Healy38ae92d2013-06-25 23:18:52 -0700619#endif
620
Uwe Kleine-König45993652011-01-19 20:47:04 +0100621 /* And last, enable the transmit and receive processing */
Shawn Guo230dec62011-09-23 02:12:48 +0000622 writel(ecntl, fep->hwp + FEC_ECNTRL);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100623 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
624
Frank Liff43da82013-01-03 16:04:23 +0000625 if (fep->bufdesc_ex)
626 fec_ptp_start_cyclecounter(ndev);
627
Uwe Kleine-König45993652011-01-19 20:47:04 +0100628 /* Enable interrupts we wish to service */
629 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
Frank Li54309fa2013-05-07 14:08:44 +0000630
631 if (netif_running(ndev)) {
Fabio Estevam31691342013-05-15 07:06:26 +0000632 netif_tx_unlock_bh(ndev);
Frank Li54309fa2013-05-07 14:08:44 +0000633 netif_wake_queue(ndev);
Fabio Estevam1ed0d562013-05-15 07:06:27 +0000634 napi_enable(&fep->napi);
635 netif_device_attach(ndev);
Frank Li54309fa2013-05-07 14:08:44 +0000636 }
Uwe Kleine-König45993652011-01-19 20:47:04 +0100637}
638
639static void
640fec_stop(struct net_device *ndev)
641{
642 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo230dec62011-09-23 02:12:48 +0000643 const struct platform_device_id *id_entry =
644 platform_get_device_id(fep->pdev);
Lothar Waßmann42431dc2011-12-07 21:59:30 +0000645 u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
Uwe Kleine-König45993652011-01-19 20:47:04 +0100646
647 /* We cannot expect a graceful transmit stop without link !!! */
648 if (fep->link) {
649 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
650 udelay(10);
651 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
Joe Perches31b77202013-04-13 19:03:17 +0000652 netdev_err(ndev, "Graceful transmit stop did not complete!\n");
Uwe Kleine-König45993652011-01-19 20:47:04 +0100653 }
654
655 /* Whack a reset. We should wait for this. */
656 writel(1, fep->hwp + FEC_ECNTRL);
657 udelay(10);
658 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
659 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
Shawn Guo230dec62011-09-23 02:12:48 +0000660
661 /* We have to keep ENET enabled to have MII interrupt stay working */
Lothar Waßmann42431dc2011-12-07 21:59:30 +0000662 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
Shawn Guo230dec62011-09-23 02:12:48 +0000663 writel(2, fep->hwp + FEC_ECNTRL);
Lothar Waßmann42431dc2011-12-07 21:59:30 +0000664 writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
665 }
Uwe Kleine-König45993652011-01-19 20:47:04 +0100666}
667
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669static void
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100670fec_timeout(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100672 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100674 ndev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Frank Li54309fa2013-05-07 14:08:44 +0000676 fep->delay_work.timeout = true;
677 schedule_delayed_work(&(fep->delay_work.delay_work), 0);
678}
679
680static void fec_enet_work(struct work_struct *work)
681{
682 struct fec_enet_private *fep =
683 container_of(work,
684 struct fec_enet_private,
685 delay_work.delay_work.work);
686
687 if (fep->delay_work.timeout) {
688 fep->delay_work.timeout = false;
689 fec_restart(fep->netdev, fep->full_duplex);
690 netif_wake_queue(fep->netdev);
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694static void
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100695fec_enet_tx(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 struct fec_enet_private *fep;
Sascha Hauer2e285322009-04-15 01:32:16 +0000698 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000699 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 struct sk_buff *skb;
Frank Lide5fb0a2013-03-03 17:34:25 +0000701 int index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100703 fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 bdp = fep->dirty_tx;
705
Frank Lide5fb0a2013-03-03 17:34:25 +0000706 /* get next bdp of dirty_tx */
707 if (bdp->cbd_sc & BD_ENET_TX_WRAP)
708 bdp = fep->tx_bd_base;
709 else
710 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
711
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000712 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
Frank Lide5fb0a2013-03-03 17:34:25 +0000713
714 /* current queue is empty */
715 if (bdp == fep->cur_tx)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +0000716 break;
717
Frank Lide5fb0a2013-03-03 17:34:25 +0000718 if (fep->bufdesc_ex)
719 index = (struct bufdesc_ex *)bdp -
720 (struct bufdesc_ex *)fep->tx_bd_base;
721 else
722 index = bdp - fep->tx_bd_base;
723
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +0100724 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
725 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +0000726 bdp->cbd_bufaddr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Frank Lide5fb0a2013-03-03 17:34:25 +0000728 skb = fep->tx_skbuff[index];
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000731 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 BD_ENET_TX_RL | BD_ENET_TX_UN |
733 BD_ENET_TX_CSL)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100734 ndev->stats.tx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000735 if (status & BD_ENET_TX_HB) /* No heartbeat */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100736 ndev->stats.tx_heartbeat_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000737 if (status & BD_ENET_TX_LC) /* Late collision */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100738 ndev->stats.tx_window_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000739 if (status & BD_ENET_TX_RL) /* Retrans limit */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100740 ndev->stats.tx_aborted_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000741 if (status & BD_ENET_TX_UN) /* Underrun */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100742 ndev->stats.tx_fifo_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000743 if (status & BD_ENET_TX_CSL) /* Carrier lost */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100744 ndev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 } else {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100746 ndev->stats.tx_packets++;
Jim Baxter06efce72013-06-27 19:25:08 +0100747 ndev->stats.tx_bytes += bdp->cbd_datlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749
Frank Liff43da82013-01-03 16:04:23 +0000750 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
751 fep->bufdesc_ex) {
Frank Li6605b732012-10-30 18:25:31 +0000752 struct skb_shared_hwtstamps shhwtstamps;
753 unsigned long flags;
Frank Liff43da82013-01-03 16:04:23 +0000754 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
Frank Li6605b732012-10-30 18:25:31 +0000755
756 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
757 spin_lock_irqsave(&fep->tmreg_lock, flags);
758 shhwtstamps.hwtstamp = ns_to_ktime(
Frank Liff43da82013-01-03 16:04:23 +0000759 timecounter_cyc2time(&fep->tc, ebdp->ts));
Frank Li6605b732012-10-30 18:25:31 +0000760 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
761 skb_tstamp_tx(skb, &shhwtstamps);
762 }
Frank Liff43da82013-01-03 16:04:23 +0000763
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000764 if (status & BD_ENET_TX_READY)
Joe Perches31b77202013-04-13 19:03:17 +0000765 netdev_err(ndev, "HEY! Enet xmit interrupt and TX_READY\n");
Sascha Hauer22f6b862009-04-15 01:32:18 +0000766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 /* Deferred means some collisions occurred during transmit,
768 * but we eventually sent the packet OK.
769 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000770 if (status & BD_ENET_TX_DEF)
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100771 ndev->stats.collisions++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400772
Sascha Hauer22f6b862009-04-15 01:32:18 +0000773 /* Free the sk buffer associated with this last transmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 dev_kfree_skb_any(skb);
Frank Lide5fb0a2013-03-03 17:34:25 +0000775 fep->tx_skbuff[index] = NULL;
776
777 fep->dirty_tx = bdp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400778
Sascha Hauer22f6b862009-04-15 01:32:18 +0000779 /* Update pointer to next buffer descriptor to be transmitted */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000780 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 bdp = fep->tx_bd_base;
782 else
Frank Liff43da82013-01-03 16:04:23 +0000783 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400784
Sascha Hauer22f6b862009-04-15 01:32:18 +0000785 /* Since we have freed up a buffer, the ring is no longer full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 */
Frank Lide5fb0a2013-03-03 17:34:25 +0000787 if (fep->dirty_tx != fep->cur_tx) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100788 if (netif_queue_stopped(ndev))
789 netif_wake_queue(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791 }
Frank Lide5fb0a2013-03-03 17:34:25 +0000792 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
795
796/* During a receive, the cur_rx points to the current incoming buffer.
797 * When we update through the ring, if the next incoming buffer has
798 * not been given to the system, we just set the empty indicator,
799 * effectively tossing the packet.
800 */
Frank Lidc975382013-01-28 18:31:42 +0000801static int
802fec_enet_rx(struct net_device *ndev, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100804 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guob5680e02011-01-05 21:13:13 +0000805 const struct platform_device_id *id_entry =
806 platform_get_device_id(fep->pdev);
Sascha Hauer2e285322009-04-15 01:32:16 +0000807 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000808 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 struct sk_buff *skb;
810 ushort pkt_len;
811 __u8 *data;
Frank Lidc975382013-01-28 18:31:42 +0000812 int pkt_received = 0;
Jim Baxtercdffcf12013-07-02 22:52:56 +0100813 struct bufdesc_ex *ebdp = NULL;
814 bool vlan_packet_rcvd = false;
815 u16 vlan_tag;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400816
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000817#ifdef CONFIG_M532x
818 flush_cache_all();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400819#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 /* First, grab all of the stats for the incoming packet.
822 * These get messed up if we get called due to a busy condition.
823 */
824 bdp = fep->cur_rx;
825
Sascha Hauer22f6b862009-04-15 01:32:18 +0000826 while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Frank Lidc975382013-01-28 18:31:42 +0000828 if (pkt_received >= budget)
829 break;
830 pkt_received++;
831
Sascha Hauer22f6b862009-04-15 01:32:18 +0000832 /* Since we have allocated space to hold a complete frame,
833 * the last indicator should be set.
834 */
835 if ((status & BD_ENET_RX_LAST) == 0)
Joe Perches31b77202013-04-13 19:03:17 +0000836 netdev_err(ndev, "rcv is not +last\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Sascha Hauer22f6b862009-04-15 01:32:18 +0000838 if (!fep->opened)
839 goto rx_processing_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Sascha Hauer22f6b862009-04-15 01:32:18 +0000841 /* Check for errors. */
842 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100844 ndev->stats.rx_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000845 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
846 /* Frame too long or too short. */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100847 ndev->stats.rx_length_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000848 }
849 if (status & BD_ENET_RX_NO) /* Frame alignment */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100850 ndev->stats.rx_frame_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000851 if (status & BD_ENET_RX_CR) /* CRC Error */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100852 ndev->stats.rx_crc_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000853 if (status & BD_ENET_RX_OV) /* FIFO overrun */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100854 ndev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
Sascha Hauer22f6b862009-04-15 01:32:18 +0000856
857 /* Report late collisions as a frame error.
858 * On this error, the BD is closed, but we don't know what we
859 * have in the buffer. So, just drop this frame on the floor.
860 */
861 if (status & BD_ENET_RX_CL) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100862 ndev->stats.rx_errors++;
863 ndev->stats.rx_frame_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000864 goto rx_processing_done;
865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Sascha Hauer22f6b862009-04-15 01:32:18 +0000867 /* Process the incoming frame. */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100868 ndev->stats.rx_packets++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000869 pkt_len = bdp->cbd_datlen;
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100870 ndev->stats.rx_bytes += pkt_len;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000871 data = (__u8*)__va(bdp->cbd_bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +0100873 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
874 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
Sascha Hauerccdc4f12009-01-28 23:03:09 +0000875
Shawn Guob5680e02011-01-05 21:13:13 +0000876 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
877 swap_buffer(data, pkt_len);
878
Jim Baxtercdffcf12013-07-02 22:52:56 +0100879 /* Extract the enhanced buffer descriptor */
880 ebdp = NULL;
881 if (fep->bufdesc_ex)
882 ebdp = (struct bufdesc_ex *)bdp;
883
884 /* If this is a VLAN packet remove the VLAN Tag */
885 vlan_packet_rcvd = false;
886 if ((ndev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
887 fep->bufdesc_ex && (ebdp->cbd_esc & BD_ENET_RX_VLAN)) {
888 /* Push and remove the vlan tag */
889 struct vlan_hdr *vlan_header =
890 (struct vlan_hdr *) (data + ETH_HLEN);
891 vlan_tag = ntohs(vlan_header->h_vlan_TCI);
892 pkt_len -= VLAN_HLEN;
893
894 vlan_packet_rcvd = true;
895 }
896
Sascha Hauer22f6b862009-04-15 01:32:18 +0000897 /* This does 16 byte alignment, exactly what we need.
898 * The packet length includes FCS, but we don't want to
899 * include that when passing upstream as it messes up
900 * bridging applications.
901 */
Fabio Estevamb72061a2012-02-07 08:27:31 +0000902 skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Sascha Hauer85498892009-04-15 01:32:21 +0000904 if (unlikely(!skb)) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100905 ndev->stats.rx_dropped++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000906 } else {
Jim Baxtercdffcf12013-07-02 22:52:56 +0100907 int payload_offset = (2 * ETH_ALEN);
Sascha Hauer85498892009-04-15 01:32:21 +0000908 skb_reserve(skb, NET_IP_ALIGN);
Sascha Hauer22f6b862009-04-15 01:32:18 +0000909 skb_put(skb, pkt_len - 4); /* Make room */
Jim Baxtercdffcf12013-07-02 22:52:56 +0100910
911 /* Extract the frame data without the VLAN header. */
912 skb_copy_to_linear_data(skb, data, (2 * ETH_ALEN));
913 if (vlan_packet_rcvd)
914 payload_offset = (2 * ETH_ALEN) + VLAN_HLEN;
915 skb_copy_to_linear_data_offset(skb, (2 * ETH_ALEN),
916 data + payload_offset,
917 pkt_len - 4 - (2 * ETH_ALEN));
918
Uwe Kleine-Königc5561672011-01-19 11:58:12 +0100919 skb->protocol = eth_type_trans(skb, ndev);
Frank Liff43da82013-01-03 16:04:23 +0000920
Frank Li6605b732012-10-30 18:25:31 +0000921 /* Get receive timestamp from the skb */
Frank Liff43da82013-01-03 16:04:23 +0000922 if (fep->hwts_rx_en && fep->bufdesc_ex) {
Frank Li6605b732012-10-30 18:25:31 +0000923 struct skb_shared_hwtstamps *shhwtstamps =
924 skb_hwtstamps(skb);
925 unsigned long flags;
926
927 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
928
929 spin_lock_irqsave(&fep->tmreg_lock, flags);
930 shhwtstamps->hwtstamp = ns_to_ktime(
Frank Liff43da82013-01-03 16:04:23 +0000931 timecounter_cyc2time(&fep->tc, ebdp->ts));
Frank Li6605b732012-10-30 18:25:31 +0000932 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
933 }
Frank Liff43da82013-01-03 16:04:23 +0000934
Jim Baxter4c09eed2013-04-19 08:10:49 +0000935 if (fep->bufdesc_ex &&
Jim Baxtercdffcf12013-07-02 22:52:56 +0100936 (fep->csum_flags & FLAG_RX_CSUM_ENABLED)) {
Jim Baxter4c09eed2013-04-19 08:10:49 +0000937 if (!(ebdp->cbd_esc & FLAG_RX_CSUM_ERROR)) {
938 /* don't check it */
939 skb->ip_summed = CHECKSUM_UNNECESSARY;
940 } else {
941 skb_checksum_none_assert(skb);
942 }
943 }
944
Jim Baxtercdffcf12013-07-02 22:52:56 +0100945 /* Handle received VLAN packets */
946 if (vlan_packet_rcvd)
947 __vlan_hwaccel_put_tag(skb,
948 htons(ETH_P_8021Q),
949 vlan_tag);
950
Richard Cochran18a03b92011-06-12 02:18:59 +0000951 if (!skb_defer_rx_timestamp(skb))
Frank Lidc975382013-01-28 18:31:42 +0000952 napi_gro_receive(&fep->napi, skb);
Sascha Hauer22f6b862009-04-15 01:32:18 +0000953 }
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +0000954
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +0100955 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
956 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
Sascha Hauer22f6b862009-04-15 01:32:18 +0000957rx_processing_done:
958 /* Clear the status flags for this buffer */
959 status &= ~BD_ENET_RX_STATS;
960
961 /* Mark the buffer empty */
962 status |= BD_ENET_RX_EMPTY;
963 bdp->cbd_sc = status;
964
Frank Liff43da82013-01-03 16:04:23 +0000965 if (fep->bufdesc_ex) {
966 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
967
968 ebdp->cbd_esc = BD_ENET_RX_INT;
969 ebdp->cbd_prot = 0;
970 ebdp->cbd_bdu = 0;
971 }
Frank Li6605b732012-10-30 18:25:31 +0000972
Sascha Hauer22f6b862009-04-15 01:32:18 +0000973 /* Update BD pointer to next entry */
974 if (status & BD_ENET_RX_WRAP)
975 bdp = fep->rx_bd_base;
976 else
Frank Liff43da82013-01-03 16:04:23 +0000977 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Sascha Hauer22f6b862009-04-15 01:32:18 +0000978 /* Doing this here will keep the FEC running while we process
979 * incoming frames. On a heavily loaded network, we should be
980 * able to keep up at the expense of system resources.
981 */
982 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
Sascha Hauer2e285322009-04-15 01:32:16 +0000984 fep->cur_rx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Frank Lidc975382013-01-28 18:31:42 +0000986 return pkt_received;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
988
Uwe Kleine-König45993652011-01-19 20:47:04 +0100989static irqreturn_t
990fec_enet_interrupt(int irq, void *dev_id)
991{
992 struct net_device *ndev = dev_id;
993 struct fec_enet_private *fep = netdev_priv(ndev);
994 uint int_events;
995 irqreturn_t ret = IRQ_NONE;
996
997 do {
998 int_events = readl(fep->hwp + FEC_IEVENT);
999 writel(int_events, fep->hwp + FEC_IEVENT);
1000
Frank Lide5fb0a2013-03-03 17:34:25 +00001001 if (int_events & (FEC_ENET_RXF | FEC_ENET_TXF)) {
Uwe Kleine-König45993652011-01-19 20:47:04 +01001002 ret = IRQ_HANDLED;
Frank Lidc975382013-01-28 18:31:42 +00001003
1004 /* Disable the RX interrupt */
1005 if (napi_schedule_prep(&fep->napi)) {
1006 writel(FEC_RX_DISABLED_IMASK,
1007 fep->hwp + FEC_IMASK);
1008 __napi_schedule(&fep->napi);
1009 }
Uwe Kleine-König45993652011-01-19 20:47:04 +01001010 }
1011
Uwe Kleine-König45993652011-01-19 20:47:04 +01001012 if (int_events & FEC_ENET_MII) {
1013 ret = IRQ_HANDLED;
1014 complete(&fep->mdio_done);
1015 }
1016 } while (int_events);
1017
1018 return ret;
1019}
1020
Frank Lidc975382013-01-28 18:31:42 +00001021static int fec_enet_rx_napi(struct napi_struct *napi, int budget)
1022{
1023 struct net_device *ndev = napi->dev;
1024 int pkts = fec_enet_rx(ndev, budget);
1025 struct fec_enet_private *fep = netdev_priv(ndev);
Uwe Kleine-König45993652011-01-19 20:47:04 +01001026
Frank Lide5fb0a2013-03-03 17:34:25 +00001027 fec_enet_tx(ndev);
1028
Frank Lidc975382013-01-28 18:31:42 +00001029 if (pkts < budget) {
1030 napi_complete(napi);
1031 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
1032 }
1033 return pkts;
1034}
Uwe Kleine-König45993652011-01-19 20:47:04 +01001035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036/* ------------------------------------------------------------------------- */
Fabio Estevam0c7768a2013-01-07 17:42:56 +00001037static void fec_get_mac(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001039 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo49da97d2011-01-05 21:13:11 +00001040 struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001041 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Shawn Guo49da97d2011-01-05 21:13:11 +00001043 /*
1044 * try to get mac address in following order:
1045 *
1046 * 1) module parameter via kernel command line in form
1047 * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
1048 */
1049 iap = macaddr;
1050
1051 /*
Shawn Guoca2cc332011-06-25 02:04:35 +08001052 * 2) from device tree data
1053 */
1054 if (!is_valid_ether_addr(iap)) {
1055 struct device_node *np = fep->pdev->dev.of_node;
1056 if (np) {
1057 const char *mac = of_get_mac_address(np);
1058 if (mac)
1059 iap = (unsigned char *) mac;
1060 }
1061 }
Shawn Guoca2cc332011-06-25 02:04:35 +08001062
1063 /*
1064 * 3) from flash or fuse (via platform data)
Shawn Guo49da97d2011-01-05 21:13:11 +00001065 */
1066 if (!is_valid_ether_addr(iap)) {
1067#ifdef CONFIG_M5272
1068 if (FEC_FLASHMAC)
1069 iap = (unsigned char *)FEC_FLASHMAC;
1070#else
1071 if (pdata)
Lothar Waßmann589efdc2011-12-07 21:59:29 +00001072 iap = (unsigned char *)&pdata->mac;
Shawn Guo49da97d2011-01-05 21:13:11 +00001073#endif
1074 }
1075
1076 /*
Shawn Guoca2cc332011-06-25 02:04:35 +08001077 * 4) FEC mac registers set by bootloader
Shawn Guo49da97d2011-01-05 21:13:11 +00001078 */
1079 if (!is_valid_ether_addr(iap)) {
1080 *((unsigned long *) &tmpaddr[0]) =
1081 be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
1082 *((unsigned short *) &tmpaddr[4]) =
1083 be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 iap = &tmpaddr[0];
1085 }
1086
Lucas Stachff5b2fa2013-06-03 00:38:39 +00001087 /*
1088 * 5) random mac address
1089 */
1090 if (!is_valid_ether_addr(iap)) {
1091 /* Report it and use a random ethernet address instead */
1092 netdev_err(ndev, "Invalid MAC address: %pM\n", iap);
1093 eth_hw_addr_random(ndev);
1094 netdev_info(ndev, "Using random MAC address: %pM\n",
1095 ndev->dev_addr);
1096 return;
1097 }
1098
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001099 memcpy(ndev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Shawn Guo49da97d2011-01-05 21:13:11 +00001101 /* Adjust MAC if using macaddr */
1102 if (iap == macaddr)
Shawn Guo43af9402011-12-05 05:01:15 +00001103 ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106/* ------------------------------------------------------------------------- */
1107
Bryan Wue6b043d2010-03-31 02:10:44 +00001108/*
1109 * Phy section
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001111static void fec_enet_adjust_link(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001113 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001114 struct phy_device *phy_dev = fep->phy_dev;
Bryan Wue6b043d2010-03-31 02:10:44 +00001115 int status_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Bryan Wue6b043d2010-03-31 02:10:44 +00001117 /* Prevent a state halted on mii error */
1118 if (fep->mii_timeout && phy_dev->state == PHY_HALTED) {
1119 phy_dev->state = PHY_RESUMING;
Frank Li54309fa2013-05-07 14:08:44 +00001120 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001122
Bryan Wue6b043d2010-03-31 02:10:44 +00001123 if (phy_dev->link) {
Lucas Stachd97e7492013-03-14 05:12:01 +00001124 if (!fep->link) {
Lothar Waßmann6ea07222011-12-07 21:59:27 +00001125 fep->link = phy_dev->link;
Bryan Wue6b043d2010-03-31 02:10:44 +00001126 status_change = 1;
1127 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001128
Lucas Stachd97e7492013-03-14 05:12:01 +00001129 if (fep->full_duplex != phy_dev->duplex)
1130 status_change = 1;
1131
1132 if (phy_dev->speed != fep->speed) {
1133 fep->speed = phy_dev->speed;
1134 status_change = 1;
1135 }
1136
1137 /* if any of the above changed restart the FEC */
1138 if (status_change)
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001139 fec_restart(ndev, phy_dev->duplex);
Lucas Stachd97e7492013-03-14 05:12:01 +00001140 } else {
1141 if (fep->link) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001142 fec_stop(ndev);
Lucas Stach8d7ed0f2013-04-16 00:42:42 +00001143 fep->link = phy_dev->link;
Lucas Stachd97e7492013-03-14 05:12:01 +00001144 status_change = 1;
1145 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001146 }
1147
Bryan Wue6b043d2010-03-31 02:10:44 +00001148 if (status_change)
1149 phy_print_status(phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Bryan Wue6b043d2010-03-31 02:10:44 +00001152static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
Bryan Wue6b043d2010-03-31 02:10:44 +00001154 struct fec_enet_private *fep = bus->priv;
Baruch Siach97b72e42010-07-11 21:12:51 +00001155 unsigned long time_left;
Bryan Wue6b043d2010-03-31 02:10:44 +00001156
1157 fep->mii_timeout = 0;
Baruch Siach97b72e42010-07-11 21:12:51 +00001158 init_completion(&fep->mdio_done);
Bryan Wue6b043d2010-03-31 02:10:44 +00001159
1160 /* start a read op */
1161 writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
1162 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1163 FEC_MMFR_TA, fep->hwp + FEC_MII_DATA);
1164
1165 /* wait for end of transfer */
Baruch Siach97b72e42010-07-11 21:12:51 +00001166 time_left = wait_for_completion_timeout(&fep->mdio_done,
1167 usecs_to_jiffies(FEC_MII_TIMEOUT));
1168 if (time_left == 0) {
1169 fep->mii_timeout = 1;
Joe Perches31b77202013-04-13 19:03:17 +00001170 netdev_err(fep->netdev, "MDIO read timeout\n");
Baruch Siach97b72e42010-07-11 21:12:51 +00001171 return -ETIMEDOUT;
Bryan Wue6b043d2010-03-31 02:10:44 +00001172 }
1173
1174 /* return value */
1175 return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA));
1176}
1177
1178static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
1179 u16 value)
1180{
1181 struct fec_enet_private *fep = bus->priv;
Baruch Siach97b72e42010-07-11 21:12:51 +00001182 unsigned long time_left;
Bryan Wue6b043d2010-03-31 02:10:44 +00001183
1184 fep->mii_timeout = 0;
Baruch Siach97b72e42010-07-11 21:12:51 +00001185 init_completion(&fep->mdio_done);
Bryan Wue6b043d2010-03-31 02:10:44 +00001186
Shawn Guo862f0982011-01-05 21:13:09 +00001187 /* start a write op */
1188 writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
Bryan Wue6b043d2010-03-31 02:10:44 +00001189 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1190 FEC_MMFR_TA | FEC_MMFR_DATA(value),
1191 fep->hwp + FEC_MII_DATA);
1192
1193 /* wait for end of transfer */
Baruch Siach97b72e42010-07-11 21:12:51 +00001194 time_left = wait_for_completion_timeout(&fep->mdio_done,
1195 usecs_to_jiffies(FEC_MII_TIMEOUT));
1196 if (time_left == 0) {
1197 fep->mii_timeout = 1;
Joe Perches31b77202013-04-13 19:03:17 +00001198 netdev_err(fep->netdev, "MDIO write timeout\n");
Baruch Siach97b72e42010-07-11 21:12:51 +00001199 return -ETIMEDOUT;
Bryan Wue6b043d2010-03-31 02:10:44 +00001200 }
1201
1202 return 0;
1203}
1204
1205static int fec_enet_mdio_reset(struct mii_bus *bus)
1206{
1207 return 0;
1208}
1209
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001210static int fec_enet_mii_probe(struct net_device *ndev)
Bryan Wue6b043d2010-03-31 02:10:44 +00001211{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001212 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo230dec62011-09-23 02:12:48 +00001213 const struct platform_device_id *id_entry =
1214 platform_get_device_id(fep->pdev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001215 struct phy_device *phy_dev = NULL;
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001216 char mdio_bus_id[MII_BUS_ID_SIZE];
1217 char phy_name[MII_BUS_ID_SIZE + 3];
1218 int phy_id;
Shawn Guo43af9402011-12-05 05:01:15 +00001219 int dev_id = fep->dev_id;
Bryan Wue6b043d2010-03-31 02:10:44 +00001220
Bryan Wu418bd0d2010-05-28 03:40:39 -07001221 fep->phy_dev = NULL;
1222
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001223 /* check for attached phy */
1224 for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
1225 if ((fep->mii_bus->phy_mask & (1 << phy_id)))
1226 continue;
1227 if (fep->mii_bus->phy_map[phy_id] == NULL)
1228 continue;
1229 if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
1230 continue;
Shawn Guob5680e02011-01-05 21:13:13 +00001231 if (dev_id--)
1232 continue;
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001233 strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
1234 break;
Bryan Wue6b043d2010-03-31 02:10:44 +00001235 }
1236
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001237 if (phy_id >= PHY_MAX_ADDR) {
Joe Perches31b77202013-04-13 19:03:17 +00001238 netdev_info(ndev, "no PHY, assuming direct connection to switch\n");
Florian Fainelliea51ade92012-02-13 01:23:22 +00001239 strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001240 phy_id = 0;
1241 }
1242
Richard Zhaoa7ed07d2012-01-29 22:08:12 +00001243 snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, phy_id);
Florian Fainellif9a8f832013-01-14 00:52:52 +00001244 phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link,
Shawn Guo230dec62011-09-23 02:12:48 +00001245 fep->phy_interface);
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001246 if (IS_ERR(phy_dev)) {
Joe Perches31b77202013-04-13 19:03:17 +00001247 netdev_err(ndev, "could not attach to PHY\n");
Greg Ungerer6fcc0402010-10-11 21:03:05 +00001248 return PTR_ERR(phy_dev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001249 }
1250
1251 /* mask with MAC supported features */
Frank Libaa70a52013-01-16 16:55:58 +00001252 if (id_entry->driver_data & FEC_QUIRK_HAS_GBIT) {
Shawn Guo230dec62011-09-23 02:12:48 +00001253 phy_dev->supported &= PHY_GBIT_FEATURES;
Guenter Roeckd1391932013-06-18 10:04:59 -07001254#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00001255 phy_dev->supported |= SUPPORTED_Pause;
Guenter Roeckd1391932013-06-18 10:04:59 -07001256#endif
Frank Libaa70a52013-01-16 16:55:58 +00001257 }
Shawn Guo230dec62011-09-23 02:12:48 +00001258 else
1259 phy_dev->supported &= PHY_BASIC_FEATURES;
1260
Bryan Wue6b043d2010-03-31 02:10:44 +00001261 phy_dev->advertising = phy_dev->supported;
1262
1263 fep->phy_dev = phy_dev;
1264 fep->link = 0;
1265 fep->full_duplex = 0;
1266
Joe Perches31b77202013-04-13 19:03:17 +00001267 netdev_info(ndev, "Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1268 fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
1269 fep->phy_dev->irq);
Bryan Wu418bd0d2010-05-28 03:40:39 -07001270
Bryan Wue6b043d2010-03-31 02:10:44 +00001271 return 0;
1272}
1273
1274static int fec_enet_mii_init(struct platform_device *pdev)
1275{
Shawn Guob5680e02011-01-05 21:13:13 +00001276 static struct mii_bus *fec0_mii_bus;
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001277 struct net_device *ndev = platform_get_drvdata(pdev);
1278 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guob5680e02011-01-05 21:13:13 +00001279 const struct platform_device_id *id_entry =
1280 platform_get_device_id(fep->pdev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001281 int err = -ENXIO, i;
1282
Shawn Guob5680e02011-01-05 21:13:13 +00001283 /*
1284 * The dual fec interfaces are not equivalent with enet-mac.
1285 * Here are the differences:
1286 *
1287 * - fec0 supports MII & RMII modes while fec1 only supports RMII
1288 * - fec0 acts as the 1588 time master while fec1 is slave
1289 * - external phys can only be configured by fec0
1290 *
1291 * That is to say fec1 can not work independently. It only works
1292 * when fec0 is working. The reason behind this design is that the
1293 * second interface is added primarily for Switch mode.
1294 *
1295 * Because of the last point above, both phys are attached on fec0
1296 * mdio interface in board design, and need to be configured by
1297 * fec0 mii_bus.
1298 */
Shawn Guo43af9402011-12-05 05:01:15 +00001299 if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) {
Shawn Guob5680e02011-01-05 21:13:13 +00001300 /* fec1 uses fec0 mii_bus */
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001301 if (mii_cnt && fec0_mii_bus) {
1302 fep->mii_bus = fec0_mii_bus;
1303 mii_cnt++;
1304 return 0;
1305 }
1306 return -ENOENT;
Shawn Guob5680e02011-01-05 21:13:13 +00001307 }
1308
Bryan Wue6b043d2010-03-31 02:10:44 +00001309 fep->mii_timeout = 0;
1310
1311 /*
1312 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
Shawn Guo230dec62011-09-23 02:12:48 +00001313 *
1314 * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
1315 * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28
1316 * Reference Manual has an error on this, and gets fixed on i.MX6Q
1317 * document.
Bryan Wue6b043d2010-03-31 02:10:44 +00001318 */
Sascha Hauerf4d40de2012-03-07 09:30:49 +01001319 fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ahb), 5000000);
Shawn Guo230dec62011-09-23 02:12:48 +00001320 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1321 fep->phy_speed--;
1322 fep->phy_speed <<= 1;
Bryan Wue6b043d2010-03-31 02:10:44 +00001323 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1324
1325 fep->mii_bus = mdiobus_alloc();
1326 if (fep->mii_bus == NULL) {
1327 err = -ENOMEM;
1328 goto err_out;
1329 }
1330
1331 fep->mii_bus->name = "fec_enet_mii_bus";
1332 fep->mii_bus->read = fec_enet_mdio_read;
1333 fep->mii_bus->write = fec_enet_mdio_write;
1334 fep->mii_bus->reset = fec_enet_mdio_reset;
Florian Fainelli391420f2012-01-09 23:59:13 +00001335 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1336 pdev->name, fep->dev_id + 1);
Bryan Wue6b043d2010-03-31 02:10:44 +00001337 fep->mii_bus->priv = fep;
1338 fep->mii_bus->parent = &pdev->dev;
1339
1340 fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
1341 if (!fep->mii_bus->irq) {
1342 err = -ENOMEM;
1343 goto err_out_free_mdiobus;
1344 }
1345
1346 for (i = 0; i < PHY_MAX_ADDR; i++)
1347 fep->mii_bus->irq[i] = PHY_POLL;
1348
Bryan Wue6b043d2010-03-31 02:10:44 +00001349 if (mdiobus_register(fep->mii_bus))
1350 goto err_out_free_mdio_irq;
1351
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001352 mii_cnt++;
1353
Shawn Guob5680e02011-01-05 21:13:13 +00001354 /* save fec0 mii_bus */
1355 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1356 fec0_mii_bus = fep->mii_bus;
1357
Bryan Wue6b043d2010-03-31 02:10:44 +00001358 return 0;
1359
Bryan Wue6b043d2010-03-31 02:10:44 +00001360err_out_free_mdio_irq:
1361 kfree(fep->mii_bus->irq);
1362err_out_free_mdiobus:
1363 mdiobus_free(fep->mii_bus);
1364err_out:
1365 return err;
1366}
1367
1368static void fec_enet_mii_remove(struct fec_enet_private *fep)
1369{
Lothar Waßmanne163cc92011-12-07 21:59:31 +00001370 if (--mii_cnt == 0) {
1371 mdiobus_unregister(fep->mii_bus);
1372 kfree(fep->mii_bus->irq);
1373 mdiobus_free(fep->mii_bus);
1374 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001375}
1376
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001377static int fec_enet_get_settings(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001378 struct ethtool_cmd *cmd)
1379{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001380 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001381 struct phy_device *phydev = fep->phy_dev;
1382
1383 if (!phydev)
1384 return -ENODEV;
1385
1386 return phy_ethtool_gset(phydev, cmd);
1387}
1388
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001389static int fec_enet_set_settings(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001390 struct ethtool_cmd *cmd)
1391{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001392 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001393 struct phy_device *phydev = fep->phy_dev;
1394
1395 if (!phydev)
1396 return -ENODEV;
1397
1398 return phy_ethtool_sset(phydev, cmd);
1399}
1400
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001401static void fec_enet_get_drvinfo(struct net_device *ndev,
Bryan Wue6b043d2010-03-31 02:10:44 +00001402 struct ethtool_drvinfo *info)
1403{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001404 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Jiri Pirko7826d432013-01-06 00:44:26 +00001406 strlcpy(info->driver, fep->pdev->dev.driver->name,
1407 sizeof(info->driver));
1408 strlcpy(info->version, "Revision: 1.0", sizeof(info->version));
1409 strlcpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
Bryan Wue6b043d2010-03-31 02:10:44 +00001411
Frank Li5ebae4892013-01-06 16:25:07 +00001412static int fec_enet_get_ts_info(struct net_device *ndev,
1413 struct ethtool_ts_info *info)
1414{
1415 struct fec_enet_private *fep = netdev_priv(ndev);
1416
1417 if (fep->bufdesc_ex) {
1418
1419 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1420 SOF_TIMESTAMPING_RX_SOFTWARE |
1421 SOF_TIMESTAMPING_SOFTWARE |
1422 SOF_TIMESTAMPING_TX_HARDWARE |
1423 SOF_TIMESTAMPING_RX_HARDWARE |
1424 SOF_TIMESTAMPING_RAW_HARDWARE;
1425 if (fep->ptp_clock)
1426 info->phc_index = ptp_clock_index(fep->ptp_clock);
1427 else
1428 info->phc_index = -1;
1429
1430 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1431 (1 << HWTSTAMP_TX_ON);
1432
1433 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1434 (1 << HWTSTAMP_FILTER_ALL);
1435 return 0;
1436 } else {
1437 return ethtool_op_get_ts_info(ndev, info);
1438 }
1439}
1440
Guenter Roeckd1391932013-06-18 10:04:59 -07001441#if !defined(CONFIG_M5272)
1442
Frank Libaa70a52013-01-16 16:55:58 +00001443static void fec_enet_get_pauseparam(struct net_device *ndev,
1444 struct ethtool_pauseparam *pause)
1445{
1446 struct fec_enet_private *fep = netdev_priv(ndev);
1447
1448 pause->autoneg = (fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) != 0;
1449 pause->tx_pause = (fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) != 0;
1450 pause->rx_pause = pause->tx_pause;
1451}
1452
1453static int fec_enet_set_pauseparam(struct net_device *ndev,
1454 struct ethtool_pauseparam *pause)
1455{
1456 struct fec_enet_private *fep = netdev_priv(ndev);
1457
1458 if (pause->tx_pause != pause->rx_pause) {
1459 netdev_info(ndev,
1460 "hardware only support enable/disable both tx and rx");
1461 return -EINVAL;
1462 }
1463
1464 fep->pause_flag = 0;
1465
1466 /* tx pause must be same as rx pause */
1467 fep->pause_flag |= pause->rx_pause ? FEC_PAUSE_FLAG_ENABLE : 0;
1468 fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0;
1469
1470 if (pause->rx_pause || pause->autoneg) {
1471 fep->phy_dev->supported |= ADVERTISED_Pause;
1472 fep->phy_dev->advertising |= ADVERTISED_Pause;
1473 } else {
1474 fep->phy_dev->supported &= ~ADVERTISED_Pause;
1475 fep->phy_dev->advertising &= ~ADVERTISED_Pause;
1476 }
1477
1478 if (pause->autoneg) {
1479 if (netif_running(ndev))
1480 fec_stop(ndev);
1481 phy_start_aneg(fep->phy_dev);
1482 }
1483 if (netif_running(ndev))
1484 fec_restart(ndev, 0);
1485
1486 return 0;
1487}
1488
Chris Healy38ae92d2013-06-25 23:18:52 -07001489static const struct fec_stat {
1490 char name[ETH_GSTRING_LEN];
1491 u16 offset;
1492} fec_stats[] = {
1493 /* RMON TX */
1494 { "tx_dropped", RMON_T_DROP },
1495 { "tx_packets", RMON_T_PACKETS },
1496 { "tx_broadcast", RMON_T_BC_PKT },
1497 { "tx_multicast", RMON_T_MC_PKT },
1498 { "tx_crc_errors", RMON_T_CRC_ALIGN },
1499 { "tx_undersize", RMON_T_UNDERSIZE },
1500 { "tx_oversize", RMON_T_OVERSIZE },
1501 { "tx_fragment", RMON_T_FRAG },
1502 { "tx_jabber", RMON_T_JAB },
1503 { "tx_collision", RMON_T_COL },
1504 { "tx_64byte", RMON_T_P64 },
1505 { "tx_65to127byte", RMON_T_P65TO127 },
1506 { "tx_128to255byte", RMON_T_P128TO255 },
1507 { "tx_256to511byte", RMON_T_P256TO511 },
1508 { "tx_512to1023byte", RMON_T_P512TO1023 },
1509 { "tx_1024to2047byte", RMON_T_P1024TO2047 },
1510 { "tx_GTE2048byte", RMON_T_P_GTE2048 },
1511 { "tx_octets", RMON_T_OCTETS },
1512
1513 /* IEEE TX */
1514 { "IEEE_tx_drop", IEEE_T_DROP },
1515 { "IEEE_tx_frame_ok", IEEE_T_FRAME_OK },
1516 { "IEEE_tx_1col", IEEE_T_1COL },
1517 { "IEEE_tx_mcol", IEEE_T_MCOL },
1518 { "IEEE_tx_def", IEEE_T_DEF },
1519 { "IEEE_tx_lcol", IEEE_T_LCOL },
1520 { "IEEE_tx_excol", IEEE_T_EXCOL },
1521 { "IEEE_tx_macerr", IEEE_T_MACERR },
1522 { "IEEE_tx_cserr", IEEE_T_CSERR },
1523 { "IEEE_tx_sqe", IEEE_T_SQE },
1524 { "IEEE_tx_fdxfc", IEEE_T_FDXFC },
1525 { "IEEE_tx_octets_ok", IEEE_T_OCTETS_OK },
1526
1527 /* RMON RX */
1528 { "rx_packets", RMON_R_PACKETS },
1529 { "rx_broadcast", RMON_R_BC_PKT },
1530 { "rx_multicast", RMON_R_MC_PKT },
1531 { "rx_crc_errors", RMON_R_CRC_ALIGN },
1532 { "rx_undersize", RMON_R_UNDERSIZE },
1533 { "rx_oversize", RMON_R_OVERSIZE },
1534 { "rx_fragment", RMON_R_FRAG },
1535 { "rx_jabber", RMON_R_JAB },
1536 { "rx_64byte", RMON_R_P64 },
1537 { "rx_65to127byte", RMON_R_P65TO127 },
1538 { "rx_128to255byte", RMON_R_P128TO255 },
1539 { "rx_256to511byte", RMON_R_P256TO511 },
1540 { "rx_512to1023byte", RMON_R_P512TO1023 },
1541 { "rx_1024to2047byte", RMON_R_P1024TO2047 },
1542 { "rx_GTE2048byte", RMON_R_P_GTE2048 },
1543 { "rx_octets", RMON_R_OCTETS },
1544
1545 /* IEEE RX */
1546 { "IEEE_rx_drop", IEEE_R_DROP },
1547 { "IEEE_rx_frame_ok", IEEE_R_FRAME_OK },
1548 { "IEEE_rx_crc", IEEE_R_CRC },
1549 { "IEEE_rx_align", IEEE_R_ALIGN },
1550 { "IEEE_rx_macerr", IEEE_R_MACERR },
1551 { "IEEE_rx_fdxfc", IEEE_R_FDXFC },
1552 { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
1553};
1554
1555static void fec_enet_get_ethtool_stats(struct net_device *dev,
1556 struct ethtool_stats *stats, u64 *data)
1557{
1558 struct fec_enet_private *fep = netdev_priv(dev);
1559 int i;
1560
1561 for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
1562 data[i] = readl(fep->hwp + fec_stats[i].offset);
1563}
1564
1565static void fec_enet_get_strings(struct net_device *netdev,
1566 u32 stringset, u8 *data)
1567{
1568 int i;
1569 switch (stringset) {
1570 case ETH_SS_STATS:
1571 for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
1572 memcpy(data + i * ETH_GSTRING_LEN,
1573 fec_stats[i].name, ETH_GSTRING_LEN);
1574 break;
1575 }
1576}
1577
1578static int fec_enet_get_sset_count(struct net_device *dev, int sset)
1579{
1580 switch (sset) {
1581 case ETH_SS_STATS:
1582 return ARRAY_SIZE(fec_stats);
1583 default:
1584 return -EOPNOTSUPP;
1585 }
1586}
Guenter Roeckd1391932013-06-18 10:04:59 -07001587#endif /* !defined(CONFIG_M5272) */
Chris Healy38ae92d2013-06-25 23:18:52 -07001588
Chris Healy32bc9b42013-06-17 07:25:06 -07001589static int fec_enet_nway_reset(struct net_device *dev)
1590{
1591 struct fec_enet_private *fep = netdev_priv(dev);
1592 struct phy_device *phydev = fep->phy_dev;
1593
1594 if (!phydev)
1595 return -ENODEV;
1596
1597 return genphy_restart_aneg(phydev);
1598}
1599
stephen hemminger9b07be42012-01-04 12:59:49 +00001600static const struct ethtool_ops fec_enet_ethtool_ops = {
Guenter Roeckd1391932013-06-18 10:04:59 -07001601#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00001602 .get_pauseparam = fec_enet_get_pauseparam,
1603 .set_pauseparam = fec_enet_set_pauseparam,
Guenter Roeckd1391932013-06-18 10:04:59 -07001604#endif
Bryan Wue6b043d2010-03-31 02:10:44 +00001605 .get_settings = fec_enet_get_settings,
1606 .set_settings = fec_enet_set_settings,
1607 .get_drvinfo = fec_enet_get_drvinfo,
1608 .get_link = ethtool_op_get_link,
Frank Li5ebae4892013-01-06 16:25:07 +00001609 .get_ts_info = fec_enet_get_ts_info,
Chris Healy32bc9b42013-06-17 07:25:06 -07001610 .nway_reset = fec_enet_nway_reset,
Chris Healy38ae92d2013-06-25 23:18:52 -07001611#ifndef CONFIG_M5272
1612 .get_ethtool_stats = fec_enet_get_ethtool_stats,
1613 .get_strings = fec_enet_get_strings,
1614 .get_sset_count = fec_enet_get_sset_count,
1615#endif
Bryan Wue6b043d2010-03-31 02:10:44 +00001616};
1617
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001618static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
Bryan Wue6b043d2010-03-31 02:10:44 +00001619{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001620 struct fec_enet_private *fep = netdev_priv(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00001621 struct phy_device *phydev = fep->phy_dev;
1622
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001623 if (!netif_running(ndev))
Bryan Wue6b043d2010-03-31 02:10:44 +00001624 return -EINVAL;
1625
1626 if (!phydev)
1627 return -ENODEV;
1628
Frank Liff43da82013-01-03 16:04:23 +00001629 if (cmd == SIOCSHWTSTAMP && fep->bufdesc_ex)
Frank Li6605b732012-10-30 18:25:31 +00001630 return fec_ptp_ioctl(ndev, rq, cmd);
Frank Liff43da82013-01-03 16:04:23 +00001631
Richard Cochran28b04112010-07-17 08:48:55 +00001632 return phy_mii_ioctl(phydev, rq, cmd);
Bryan Wue6b043d2010-03-31 02:10:44 +00001633}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001635static void fec_enet_free_buffers(struct net_device *ndev)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001636{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001637 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevamda2191e2013-03-20 12:31:07 -03001638 unsigned int i;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001639 struct sk_buff *skb;
1640 struct bufdesc *bdp;
1641
1642 bdp = fep->rx_bd_base;
1643 for (i = 0; i < RX_RING_SIZE; i++) {
1644 skb = fep->rx_skbuff[i];
1645
1646 if (bdp->cbd_bufaddr)
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +01001647 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001648 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
1649 if (skb)
1650 dev_kfree_skb(skb);
Frank Liff43da82013-01-03 16:04:23 +00001651 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001652 }
1653
1654 bdp = fep->tx_bd_base;
1655 for (i = 0; i < TX_RING_SIZE; i++)
1656 kfree(fep->tx_bounce[i]);
1657}
1658
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001659static int fec_enet_alloc_buffers(struct net_device *ndev)
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001660{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001661 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevamda2191e2013-03-20 12:31:07 -03001662 unsigned int i;
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001663 struct sk_buff *skb;
1664 struct bufdesc *bdp;
1665
1666 bdp = fep->rx_bd_base;
1667 for (i = 0; i < RX_RING_SIZE; i++) {
Fabio Estevamb72061a2012-02-07 08:27:31 +00001668 skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001669 if (!skb) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001670 fec_enet_free_buffers(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001671 return -ENOMEM;
1672 }
1673 fep->rx_skbuff[i] = skb;
1674
Uwe Kleine-Königd1ab1f52011-01-20 09:26:38 +01001675 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001676 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
1677 bdp->cbd_sc = BD_ENET_RX_EMPTY;
Frank Liff43da82013-01-03 16:04:23 +00001678
1679 if (fep->bufdesc_ex) {
1680 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
1681 ebdp->cbd_esc = BD_ENET_RX_INT;
1682 }
1683
1684 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001685 }
1686
1687 /* Set the last buffer to wrap. */
Frank Liff43da82013-01-03 16:04:23 +00001688 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001689 bdp->cbd_sc |= BD_SC_WRAP;
1690
1691 bdp = fep->tx_bd_base;
1692 for (i = 0; i < TX_RING_SIZE; i++) {
1693 fep->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL);
1694
1695 bdp->cbd_sc = 0;
1696 bdp->cbd_bufaddr = 0;
Frank Li6605b732012-10-30 18:25:31 +00001697
Frank Liff43da82013-01-03 16:04:23 +00001698 if (fep->bufdesc_ex) {
1699 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
Jim Baxter96d22222013-03-26 05:25:07 +00001700 ebdp->cbd_esc = BD_ENET_TX_INT;
Frank Liff43da82013-01-03 16:04:23 +00001701 }
1702
1703 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001704 }
1705
1706 /* Set the last buffer to wrap. */
Frank Liff43da82013-01-03 16:04:23 +00001707 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001708 bdp->cbd_sc |= BD_SC_WRAP;
1709
1710 return 0;
1711}
1712
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001714fec_enet_open(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001716 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001717 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Frank Lidc975382013-01-28 18:31:42 +00001719 napi_enable(&fep->napi);
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 /* I should reset the ring buffers here, but I don't yet know
1722 * a simple way to do that.
1723 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001725 ret = fec_enet_alloc_buffers(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001726 if (ret)
1727 return ret;
1728
Bryan Wu418bd0d2010-05-28 03:40:39 -07001729 /* Probe and connect to PHY when open the interface */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001730 ret = fec_enet_mii_probe(ndev);
Bryan Wu418bd0d2010-05-28 03:40:39 -07001731 if (ret) {
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001732 fec_enet_free_buffers(ndev);
Bryan Wu418bd0d2010-05-28 03:40:39 -07001733 return ret;
1734 }
Bryan Wue6b043d2010-03-31 02:10:44 +00001735 phy_start(fep->phy_dev);
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001736 netif_start_queue(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 fep->opened = 1;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001738 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739}
1740
1741static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001742fec_enet_close(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001744 struct fec_enet_private *fep = netdev_priv(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Sascha Hauer22f6b862009-04-15 01:32:18 +00001746 /* Don't know what to do yet. */
Georg Hofmann3f104c32013-03-14 06:54:09 +00001747 napi_disable(&fep->napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 fep->opened = 0;
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001749 netif_stop_queue(ndev);
1750 fec_stop(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Uwe Kleine-Könige497ba82011-01-17 20:04:23 +01001752 if (fep->phy_dev) {
1753 phy_stop(fep->phy_dev);
Bryan Wu418bd0d2010-05-28 03:40:39 -07001754 phy_disconnect(fep->phy_dev);
Uwe Kleine-Könige497ba82011-01-17 20:04:23 +01001755 }
Bryan Wu418bd0d2010-05-28 03:40:39 -07001756
Uwe Kleine-Königdb8880b2011-01-19 20:26:39 +01001757 fec_enet_free_buffers(ndev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return 0;
1760}
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762/* Set or clear the multicast filter for this adaptor.
1763 * Skeleton taken from sunlance driver.
1764 * The CPM Ethernet implementation allows Multicast as well as individual
1765 * MAC address filtering. Some of the drivers check to make sure it is
1766 * a group multicast address, and discard those that are not. I guess I
1767 * will do the same for now, but just remove the test if you want
1768 * individual filtering as well (do the upper net layers want or support
1769 * this kind of feature?).
1770 */
1771
1772#define HASH_BITS 6 /* #bits in hash */
1773#define CRC32_POLY 0xEDB88320
1774
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001775static void set_multicast_list(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001777 struct fec_enet_private *fep = netdev_priv(ndev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001778 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001779 unsigned int i, bit, data, crc, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 unsigned char hash;
1781
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001782 if (ndev->flags & IFF_PROMISC) {
Sascha Hauerf44d6302009-04-15 03:11:30 +00001783 tmp = readl(fep->hwp + FEC_R_CNTRL);
1784 tmp |= 0x8;
1785 writel(tmp, fep->hwp + FEC_R_CNTRL);
Sascha Hauer4e831832009-04-15 01:32:19 +00001786 return;
1787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Sascha Hauer4e831832009-04-15 01:32:19 +00001789 tmp = readl(fep->hwp + FEC_R_CNTRL);
1790 tmp &= ~0x8;
1791 writel(tmp, fep->hwp + FEC_R_CNTRL);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001792
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001793 if (ndev->flags & IFF_ALLMULTI) {
Sascha Hauer4e831832009-04-15 01:32:19 +00001794 /* Catch all multicast addresses, so set the
1795 * filter to all 1's
1796 */
1797 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1798 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Sascha Hauer4e831832009-04-15 01:32:19 +00001800 return;
1801 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001802
Sascha Hauer4e831832009-04-15 01:32:19 +00001803 /* Clear filter and add the addresses in hash register
1804 */
1805 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1806 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001808 netdev_for_each_mc_addr(ha, ndev) {
Sascha Hauer4e831832009-04-15 01:32:19 +00001809 /* calculate crc32 value of mac address */
1810 crc = 0xffffffff;
1811
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001812 for (i = 0; i < ndev->addr_len; i++) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001813 data = ha->addr[i];
Sascha Hauer4e831832009-04-15 01:32:19 +00001814 for (bit = 0; bit < 8; bit++, data >>= 1) {
1815 crc = (crc >> 1) ^
1816 (((crc ^ data) & 1) ? CRC32_POLY : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 }
1818 }
Sascha Hauer4e831832009-04-15 01:32:19 +00001819
1820 /* only upper 6 bits (HASH_BITS) are used
1821 * which point to specific bit in he hash registers
1822 */
1823 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
1824
1825 if (hash > 31) {
1826 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1827 tmp |= 1 << (hash - 32);
1828 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1829 } else {
1830 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1831 tmp |= 1 << hash;
1832 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
1835}
1836
Sascha Hauer22f6b862009-04-15 01:32:18 +00001837/* Set a MAC change in hardware. */
Sascha Hauer009fda82009-04-15 01:32:23 +00001838static int
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001839fec_set_mac_address(struct net_device *ndev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001841 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Hauer009fda82009-04-15 01:32:23 +00001842 struct sockaddr *addr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Sascha Hauer009fda82009-04-15 01:32:23 +00001844 if (!is_valid_ether_addr(addr->sa_data))
1845 return -EADDRNOTAVAIL;
1846
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001847 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
Sascha Hauer009fda82009-04-15 01:32:23 +00001848
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001849 writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
1850 (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
Sascha Hauerf44d6302009-04-15 03:11:30 +00001851 fep->hwp + FEC_ADDR_LOW);
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001852 writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
Mattias Walström7cff0942010-05-05 00:55:48 -07001853 fep->hwp + FEC_ADDR_HIGH);
Sascha Hauer009fda82009-04-15 01:32:23 +00001854 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855}
1856
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00001857#ifdef CONFIG_NET_POLL_CONTROLLER
Ben Hutchings49ce9c22012-07-10 10:56:00 +00001858/**
1859 * fec_poll_controller - FEC Poll controller function
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00001860 * @dev: The FEC network adapter
1861 *
1862 * Polled functionality used by netconsole and others in non interrupt mode
1863 *
1864 */
Wei Yongjun47a52472013-03-20 05:06:11 +00001865static void fec_poll_controller(struct net_device *dev)
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00001866{
1867 int i;
1868 struct fec_enet_private *fep = netdev_priv(dev);
1869
1870 for (i = 0; i < FEC_IRQ_NUM; i++) {
1871 if (fep->irq[i] > 0) {
1872 disable_irq(fep->irq[i]);
1873 fec_enet_interrupt(fep->irq[i], dev);
1874 enable_irq(fep->irq[i]);
1875 }
1876 }
1877}
1878#endif
1879
Jim Baxter4c09eed2013-04-19 08:10:49 +00001880static int fec_set_features(struct net_device *netdev,
1881 netdev_features_t features)
1882{
1883 struct fec_enet_private *fep = netdev_priv(netdev);
1884 netdev_features_t changed = features ^ netdev->features;
1885
1886 netdev->features = features;
1887
1888 /* Receive checksum has been changed */
1889 if (changed & NETIF_F_RXCSUM) {
1890 if (features & NETIF_F_RXCSUM)
1891 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
1892 else
1893 fep->csum_flags &= ~FLAG_RX_CSUM_ENABLED;
1894
1895 if (netif_running(netdev)) {
1896 fec_stop(netdev);
1897 fec_restart(netdev, fep->phy_dev->duplex);
1898 netif_wake_queue(netdev);
1899 } else {
1900 fec_restart(netdev, fep->phy_dev->duplex);
1901 }
1902 }
1903
1904 return 0;
1905}
1906
Sascha Hauer009fda82009-04-15 01:32:23 +00001907static const struct net_device_ops fec_netdev_ops = {
1908 .ndo_open = fec_enet_open,
1909 .ndo_stop = fec_enet_close,
1910 .ndo_start_xmit = fec_enet_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001911 .ndo_set_rx_mode = set_multicast_list,
Ben Hutchings635ecaa2009-07-09 17:59:01 +00001912 .ndo_change_mtu = eth_change_mtu,
Sascha Hauer009fda82009-04-15 01:32:23 +00001913 .ndo_validate_addr = eth_validate_addr,
1914 .ndo_tx_timeout = fec_timeout,
1915 .ndo_set_mac_address = fec_set_mac_address,
Uwe Kleine-Königdb8880b2011-01-19 20:26:39 +01001916 .ndo_do_ioctl = fec_enet_ioctl,
Xiao Jiang7f5c6ad2011-09-29 02:15:57 +00001917#ifdef CONFIG_NET_POLL_CONTROLLER
1918 .ndo_poll_controller = fec_poll_controller,
1919#endif
Jim Baxter4c09eed2013-04-19 08:10:49 +00001920 .ndo_set_features = fec_set_features,
Sascha Hauer009fda82009-04-15 01:32:23 +00001921};
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 /*
1924 * XXX: We need to clean up on failure exits here.
Sascha Haueread73182009-01-28 23:03:11 +00001925 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001927static int fec_enet_init(struct net_device *ndev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001929 struct fec_enet_private *fep = netdev_priv(ndev);
Shawn Guo48496252013-05-08 21:08:22 +00001930 const struct platform_device_id *id_entry =
1931 platform_get_device_id(fep->pdev);
Sascha Hauerf0b3fbe2009-04-15 01:32:24 +00001932 struct bufdesc *cbd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00001934 /* Allocate memory for buffer descriptors. */
1935 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
Joe Perchesd0320f72013-03-14 13:07:21 +00001936 GFP_KERNEL);
1937 if (!cbd_base)
Greg Ungerer562d2f82005-11-07 14:09:50 +10001938 return -ENOMEM;
Greg Ungerer562d2f82005-11-07 14:09:50 +10001939
Frank Li14109a52013-03-26 16:12:03 +00001940 memset(cbd_base, 0, PAGE_SIZE);
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +10001941
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001942 fep->netdev = ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Shawn Guo49da97d2011-01-05 21:13:11 +00001944 /* Get the Ethernet address */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001945 fec_get_mac(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00001947 /* Set receive and transmit descriptor base. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 fep->rx_bd_base = cbd_base;
Frank Liff43da82013-01-03 16:04:23 +00001949 if (fep->bufdesc_ex)
1950 fep->tx_bd_base = (struct bufdesc *)
1951 (((struct bufdesc_ex *)cbd_base) + RX_RING_SIZE);
1952 else
1953 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Sascha Hauer22f6b862009-04-15 01:32:18 +00001955 /* The FEC Ethernet specific entries in the device structure */
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001956 ndev->watchdog_timeo = TX_TIMEOUT;
1957 ndev->netdev_ops = &fec_netdev_ops;
1958 ndev->ethtool_ops = &fec_enet_ethtool_ops;
Rob Herring633e7532010-02-05 08:56:20 +00001959
Frank Lidc975382013-01-28 18:31:42 +00001960 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK);
1961 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, FEC_NAPI_WEIGHT);
1962
Jim Baxtercdffcf12013-07-02 22:52:56 +01001963 if (id_entry->driver_data & FEC_QUIRK_HAS_VLAN) {
1964 /* enable hw VLAN support */
1965 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1966 ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
1967 }
1968
Shawn Guo48496252013-05-08 21:08:22 +00001969 if (id_entry->driver_data & FEC_QUIRK_HAS_CSUM) {
1970 /* enable hw accelerator */
1971 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
1972 | NETIF_F_RXCSUM);
1973 ndev->hw_features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
1974 | NETIF_F_RXCSUM);
1975 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
1976 }
Jim Baxter4c09eed2013-04-19 08:10:49 +00001977
Uwe Kleine-Königc5561672011-01-19 11:58:12 +01001978 fec_restart(ndev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 return 0;
1981}
1982
Shawn Guoca2cc332011-06-25 02:04:35 +08001983#ifdef CONFIG_OF
Bill Pemberton33897cc2012-12-03 09:23:58 -05001984static void fec_reset_phy(struct platform_device *pdev)
Shawn Guoca2cc332011-06-25 02:04:35 +08001985{
1986 int err, phy_reset;
Shawn Guoa3caad02012-06-27 03:45:24 +00001987 int msec = 1;
Shawn Guoca2cc332011-06-25 02:04:35 +08001988 struct device_node *np = pdev->dev.of_node;
1989
1990 if (!np)
Shawn Guoa9b2c8e2011-09-23 02:12:46 +00001991 return;
Shawn Guoca2cc332011-06-25 02:04:35 +08001992
Shawn Guoa3caad02012-06-27 03:45:24 +00001993 of_property_read_u32(np, "phy-reset-duration", &msec);
1994 /* A sane reset duration should not be longer than 1s */
1995 if (msec > 1000)
1996 msec = 1;
1997
Shawn Guoca2cc332011-06-25 02:04:35 +08001998 phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
Fabio Estevam07dcf8e2013-02-18 10:20:31 +00001999 if (!gpio_is_valid(phy_reset))
2000 return;
2001
Shawn Guo119fc002012-06-27 03:45:22 +00002002 err = devm_gpio_request_one(&pdev->dev, phy_reset,
2003 GPIOF_OUT_INIT_LOW, "phy-reset");
Shawn Guoca2cc332011-06-25 02:04:35 +08002004 if (err) {
Fabio Estevam07dcf8e2013-02-18 10:20:31 +00002005 dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
Shawn Guoa9b2c8e2011-09-23 02:12:46 +00002006 return;
Shawn Guoca2cc332011-06-25 02:04:35 +08002007 }
Shawn Guoa3caad02012-06-27 03:45:24 +00002008 msleep(msec);
Shawn Guoca2cc332011-06-25 02:04:35 +08002009 gpio_set_value(phy_reset, 1);
Shawn Guoca2cc332011-06-25 02:04:35 +08002010}
2011#else /* CONFIG_OF */
Fabio Estevam0c7768a2013-01-07 17:42:56 +00002012static void fec_reset_phy(struct platform_device *pdev)
Shawn Guoca2cc332011-06-25 02:04:35 +08002013{
2014 /*
2015 * In case of platform probe, the reset has been done
2016 * by machine code.
2017 */
Shawn Guoca2cc332011-06-25 02:04:35 +08002018}
2019#endif /* CONFIG_OF */
2020
Bill Pemberton33897cc2012-12-03 09:23:58 -05002021static int
Sascha Haueread73182009-01-28 23:03:11 +00002022fec_probe(struct platform_device *pdev)
2023{
2024 struct fec_enet_private *fep;
Baruch Siach5eb32bd2010-05-24 00:36:13 -07002025 struct fec_platform_data *pdata;
Sascha Haueread73182009-01-28 23:03:11 +00002026 struct net_device *ndev;
2027 int i, irq, ret = 0;
2028 struct resource *r;
Shawn Guoca2cc332011-06-25 02:04:35 +08002029 const struct of_device_id *of_id;
Shawn Guo43af9402011-12-05 05:01:15 +00002030 static int dev_id;
Shawn Guoca2cc332011-06-25 02:04:35 +08002031
2032 of_id = of_match_device(fec_dt_ids, &pdev->dev);
2033 if (of_id)
2034 pdev->id_entry = of_id->data;
Sascha Haueread73182009-01-28 23:03:11 +00002035
2036 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2037 if (!r)
2038 return -ENXIO;
2039
Sascha Haueread73182009-01-28 23:03:11 +00002040 /* Init network device */
2041 ndev = alloc_etherdev(sizeof(struct fec_enet_private));
Fabio Estevam83e519b2013-03-11 07:32:55 +00002042 if (!ndev)
2043 return -ENOMEM;
Sascha Haueread73182009-01-28 23:03:11 +00002044
2045 SET_NETDEV_DEV(ndev, &pdev->dev);
2046
2047 /* setup board info structure */
2048 fep = netdev_priv(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002049
Guenter Roeckd1391932013-06-18 10:04:59 -07002050#if !defined(CONFIG_M5272)
Frank Libaa70a52013-01-16 16:55:58 +00002051 /* default enable pause frame auto negotiation */
2052 if (pdev->id_entry &&
2053 (pdev->id_entry->driver_data & FEC_QUIRK_HAS_GBIT))
2054 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG;
Guenter Roeckd1391932013-06-18 10:04:59 -07002055#endif
Frank Libaa70a52013-01-16 16:55:58 +00002056
Tushar Behera941e1732013-06-10 17:05:05 +05302057 fep->hwp = devm_ioremap_resource(&pdev->dev, r);
2058 if (IS_ERR(fep->hwp)) {
2059 ret = PTR_ERR(fep->hwp);
2060 goto failed_ioremap;
2061 }
2062
Bryan Wue6b043d2010-03-31 02:10:44 +00002063 fep->pdev = pdev;
Shawn Guo43af9402011-12-05 05:01:15 +00002064 fep->dev_id = dev_id++;
Sascha Haueread73182009-01-28 23:03:11 +00002065
Frank Liff43da82013-01-03 16:04:23 +00002066 fep->bufdesc_ex = 0;
2067
Sascha Haueread73182009-01-28 23:03:11 +00002068 platform_set_drvdata(pdev, ndev);
2069
Guenter Roeck6c5f7802013-04-02 09:35:10 +00002070 ret = of_get_phy_mode(pdev->dev.of_node);
Shawn Guoca2cc332011-06-25 02:04:35 +08002071 if (ret < 0) {
2072 pdata = pdev->dev.platform_data;
2073 if (pdata)
2074 fep->phy_interface = pdata->phy;
2075 else
2076 fep->phy_interface = PHY_INTERFACE_MODE_MII;
2077 } else {
2078 fep->phy_interface = ret;
2079 }
2080
Fabio Estevame2f8d552013-02-22 06:40:45 +00002081 fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
2082 if (IS_ERR(fep->clk_ipg)) {
2083 ret = PTR_ERR(fep->clk_ipg);
2084 goto failed_clk;
2085 }
2086
2087 fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
2088 if (IS_ERR(fep->clk_ahb)) {
2089 ret = PTR_ERR(fep->clk_ahb);
2090 goto failed_clk;
2091 }
2092
Linus Torvalds38f56f32013-05-07 11:06:17 -07002093 /* enet_out is optional, depends on board */
2094 fep->clk_enet_out = devm_clk_get(&pdev->dev, "enet_out");
2095 if (IS_ERR(fep->clk_enet_out))
2096 fep->clk_enet_out = NULL;
2097
Fabio Estevame2f8d552013-02-22 06:40:45 +00002098 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp");
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002099 fep->bufdesc_ex =
2100 pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002101 if (IS_ERR(fep->clk_ptp)) {
Linus Torvalds38f56f32013-05-07 11:06:17 -07002102 fep->clk_ptp = NULL;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002103 fep->bufdesc_ex = 0;
2104 }
2105
2106 clk_prepare_enable(fep->clk_ahb);
2107 clk_prepare_enable(fep->clk_ipg);
Linus Torvalds38f56f32013-05-07 11:06:17 -07002108 clk_prepare_enable(fep->clk_enet_out);
2109 clk_prepare_enable(fep->clk_ptp);
Fabio Estevame2f8d552013-02-22 06:40:45 +00002110
Fabio Estevamf4e9f3d2013-05-27 03:48:29 +00002111 fep->reg_phy = devm_regulator_get(&pdev->dev, "phy");
2112 if (!IS_ERR(fep->reg_phy)) {
2113 ret = regulator_enable(fep->reg_phy);
Fabio Estevame2f8d552013-02-22 06:40:45 +00002114 if (ret) {
2115 dev_err(&pdev->dev,
2116 "Failed to enable phy regulator: %d\n", ret);
2117 goto failed_regulator;
2118 }
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002119 } else {
2120 fep->reg_phy = NULL;
Fabio Estevame2f8d552013-02-22 06:40:45 +00002121 }
2122
2123 fec_reset_phy(pdev);
2124
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002125 if (fep->bufdesc_ex)
Fabio Estevamca162a82013-06-07 10:48:00 +00002126 fec_ptp_init(pdev);
Fabio Estevam7f7d6c22013-02-21 09:21:50 +00002127
2128 ret = fec_enet_init(ndev);
2129 if (ret)
2130 goto failed_init;
2131
Xiao Jiangc7c83d12011-09-29 02:15:56 +00002132 for (i = 0; i < FEC_IRQ_NUM; i++) {
Sascha Haueread73182009-01-28 23:03:11 +00002133 irq = platform_get_irq(pdev, i);
Lothar Waßmann86f9f2c2011-12-07 21:59:28 +00002134 if (irq < 0) {
2135 if (i)
2136 break;
2137 ret = irq;
2138 goto failed_irq;
2139 }
Sascha Haueread73182009-01-28 23:03:11 +00002140 ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
2141 if (ret) {
Uwe Kleine-Königb2b09ad2011-01-13 21:49:05 +01002142 while (--i >= 0) {
Sascha Haueread73182009-01-28 23:03:11 +00002143 irq = platform_get_irq(pdev, i);
2144 free_irq(irq, ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002145 }
2146 goto failed_irq;
2147 }
2148 }
2149
Bryan Wue6b043d2010-03-31 02:10:44 +00002150 ret = fec_enet_mii_init(pdev);
2151 if (ret)
2152 goto failed_mii_init;
2153
Oskar Schirmer03c698c2010-10-07 02:30:30 +00002154 /* Carrier starts down, phylib will bring it up */
2155 netif_carrier_off(ndev);
2156
Sascha Haueread73182009-01-28 23:03:11 +00002157 ret = register_netdev(ndev);
2158 if (ret)
2159 goto failed_register;
2160
Fabio Estevameb1d0642013-04-13 07:25:36 +00002161 if (fep->bufdesc_ex && fep->ptp_clock)
2162 netdev_info(ndev, "registered PHC device %d\n", fep->dev_id);
2163
Frank Li54309fa2013-05-07 14:08:44 +00002164 INIT_DELAYED_WORK(&(fep->delay_work.delay_work), fec_enet_work);
Sascha Haueread73182009-01-28 23:03:11 +00002165 return 0;
2166
2167failed_register:
Bryan Wue6b043d2010-03-31 02:10:44 +00002168 fec_enet_mii_remove(fep);
2169failed_mii_init:
Fabio Estevam7a2bbd82013-05-27 03:48:30 +00002170failed_irq:
Fabio Estevame2f8d552013-02-22 06:40:45 +00002171 for (i = 0; i < FEC_IRQ_NUM; i++) {
2172 irq = platform_get_irq(pdev, i);
2173 if (irq > 0)
2174 free_irq(irq, ndev);
2175 }
Fabio Estevam7a2bbd82013-05-27 03:48:30 +00002176failed_init:
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002177 if (fep->reg_phy)
2178 regulator_disable(fep->reg_phy);
Shawn Guo5fa9c0f2012-06-27 03:45:21 +00002179failed_regulator:
Sascha Hauerf4d40de2012-03-07 09:30:49 +01002180 clk_disable_unprepare(fep->clk_ahb);
2181 clk_disable_unprepare(fep->clk_ipg);
Linus Torvalds38f56f32013-05-07 11:06:17 -07002182 clk_disable_unprepare(fep->clk_enet_out);
2183 clk_disable_unprepare(fep->clk_ptp);
Sascha Haueread73182009-01-28 23:03:11 +00002184failed_clk:
Sascha Haueread73182009-01-28 23:03:11 +00002185failed_ioremap:
2186 free_netdev(ndev);
2187
2188 return ret;
2189}
2190
Bill Pemberton33897cc2012-12-03 09:23:58 -05002191static int
Sascha Haueread73182009-01-28 23:03:11 +00002192fec_drv_remove(struct platform_device *pdev)
2193{
2194 struct net_device *ndev = platform_get_drvdata(pdev);
2195 struct fec_enet_private *fep = netdev_priv(ndev);
Lothar Waßmanne163cc92011-12-07 21:59:31 +00002196 int i;
Sascha Haueread73182009-01-28 23:03:11 +00002197
Frank Li54309fa2013-05-07 14:08:44 +00002198 cancel_delayed_work_sync(&(fep->delay_work.delay_work));
Lothar Waßmanne163cc92011-12-07 21:59:31 +00002199 unregister_netdev(ndev);
Bryan Wue6b043d2010-03-31 02:10:44 +00002200 fec_enet_mii_remove(fep);
Frank Li6605b732012-10-30 18:25:31 +00002201 del_timer_sync(&fep->time_keep);
Fabio Estevamc55284e2013-05-27 03:48:32 +00002202 for (i = 0; i < FEC_IRQ_NUM; i++) {
2203 int irq = platform_get_irq(pdev, i);
2204 if (irq > 0)
2205 free_irq(irq, ndev);
2206 }
Fabio Estevamf6a4d602013-05-27 03:48:31 +00002207 if (fep->reg_phy)
2208 regulator_disable(fep->reg_phy);
Frank Li6605b732012-10-30 18:25:31 +00002209 clk_disable_unprepare(fep->clk_ptp);
2210 if (fep->ptp_clock)
2211 ptp_clock_unregister(fep->ptp_clock);
Linus Torvalds38f56f32013-05-07 11:06:17 -07002212 clk_disable_unprepare(fep->clk_enet_out);
Sascha Hauerf4d40de2012-03-07 09:30:49 +01002213 clk_disable_unprepare(fep->clk_ahb);
2214 clk_disable_unprepare(fep->clk_ipg);
Sascha Haueread73182009-01-28 23:03:11 +00002215 free_netdev(ndev);
Uwe Kleine-König28e21882011-01-13 21:44:18 +01002216
Sascha Haueread73182009-01-28 23:03:11 +00002217 return 0;
2218}
2219
Fabio Estevambf7bfd72013-04-16 08:17:46 +00002220#ifdef CONFIG_PM_SLEEP
Sascha Haueread73182009-01-28 23:03:11 +00002221static int
Eric Benard87cad5c2010-06-18 04:19:54 +00002222fec_suspend(struct device *dev)
Sascha Haueread73182009-01-28 23:03:11 +00002223{
Eric Benard87cad5c2010-06-18 04:19:54 +00002224 struct net_device *ndev = dev_get_drvdata(dev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002225 struct fec_enet_private *fep = netdev_priv(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002226
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002227 if (netif_running(ndev)) {
2228 fec_stop(ndev);
2229 netif_device_detach(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002230 }
Linus Torvalds38f56f32013-05-07 11:06:17 -07002231 clk_disable_unprepare(fep->clk_enet_out);
Sascha Hauerf4d40de2012-03-07 09:30:49 +01002232 clk_disable_unprepare(fep->clk_ahb);
2233 clk_disable_unprepare(fep->clk_ipg);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002234
Fabio Estevam238f7bc2013-05-27 03:48:33 +00002235 if (fep->reg_phy)
2236 regulator_disable(fep->reg_phy);
2237
Sascha Haueread73182009-01-28 23:03:11 +00002238 return 0;
2239}
2240
2241static int
Eric Benard87cad5c2010-06-18 04:19:54 +00002242fec_resume(struct device *dev)
Sascha Haueread73182009-01-28 23:03:11 +00002243{
Eric Benard87cad5c2010-06-18 04:19:54 +00002244 struct net_device *ndev = dev_get_drvdata(dev);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002245 struct fec_enet_private *fep = netdev_priv(ndev);
Fabio Estevam238f7bc2013-05-27 03:48:33 +00002246 int ret;
2247
2248 if (fep->reg_phy) {
2249 ret = regulator_enable(fep->reg_phy);
2250 if (ret)
2251 return ret;
2252 }
Sascha Haueread73182009-01-28 23:03:11 +00002253
Linus Torvalds38f56f32013-05-07 11:06:17 -07002254 clk_prepare_enable(fep->clk_enet_out);
Sascha Hauerf4d40de2012-03-07 09:30:49 +01002255 clk_prepare_enable(fep->clk_ahb);
2256 clk_prepare_enable(fep->clk_ipg);
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002257 if (netif_running(ndev)) {
2258 fec_restart(ndev, fep->full_duplex);
2259 netif_device_attach(ndev);
Sascha Haueread73182009-01-28 23:03:11 +00002260 }
Uwe Kleine-König04e52162011-01-13 21:53:40 +01002261
Sascha Haueread73182009-01-28 23:03:11 +00002262 return 0;
2263}
Fabio Estevambf7bfd72013-04-16 08:17:46 +00002264#endif /* CONFIG_PM_SLEEP */
Sascha Haueread73182009-01-28 23:03:11 +00002265
Fabio Estevambf7bfd72013-04-16 08:17:46 +00002266static SIMPLE_DEV_PM_OPS(fec_pm_ops, fec_suspend, fec_resume);
Denis Kirjanov59d42892010-06-02 09:27:04 +00002267
Sascha Haueread73182009-01-28 23:03:11 +00002268static struct platform_driver fec_driver = {
2269 .driver = {
Shawn Guob5680e02011-01-05 21:13:13 +00002270 .name = DRIVER_NAME,
Eric Benard87cad5c2010-06-18 04:19:54 +00002271 .owner = THIS_MODULE,
Eric Benard87cad5c2010-06-18 04:19:54 +00002272 .pm = &fec_pm_ops,
Shawn Guoca2cc332011-06-25 02:04:35 +08002273 .of_match_table = fec_dt_ids,
Sascha Haueread73182009-01-28 23:03:11 +00002274 },
Shawn Guob5680e02011-01-05 21:13:13 +00002275 .id_table = fec_devtype,
Eric Benard87cad5c2010-06-18 04:19:54 +00002276 .probe = fec_probe,
Bill Pemberton33897cc2012-12-03 09:23:58 -05002277 .remove = fec_drv_remove,
Sascha Haueread73182009-01-28 23:03:11 +00002278};
2279
Fabio Estevamaaca2372012-01-23 16:44:50 +00002280module_platform_driver(fec_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Fabio Estevamf8c0aca2013-07-20 16:20:36 -03002282MODULE_ALIAS("platform:"DRIVER_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283MODULE_LICENSE("GPL");