]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/net/ethernet/freescale/fec_main.c
3c59x: consolidate error cleanup in vortex_init_one()
[mirror_ubuntu-jammy-kernel.git] / drivers / net / ethernet / freescale / fec_main.c
CommitLineData
1da177e4
LT
1/*
2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
4 *
7dd6a2aa 5 * Right now, I am very wasteful with the buffers. I allocate memory
1da177e4
LT
6 * 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 *
562d2f8c
GU
15 * Support for FEC controller of ColdFire processors.
16 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
7dd6a2aa
GU
17 *
18 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
677177c5 19 * Copyright (c) 2004-2006 Macq Electronique SA.
b5680e0b 20 *
230dec61 21 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
1da177e4
LT
22 */
23
1da177e4
LT
24#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>
1da177e4
LT
32#include <linux/init.h>
33#include <linux/delay.h>
34#include <linux/netdevice.h>
35#include <linux/etherdevice.h>
36#include <linux/skbuff.h>
4c09eed9
JB
37#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>
1da177e4
LT
43#include <linux/spinlock.h>
44#include <linux/workqueue.h>
45#include <linux/bitops.h>
6f501b17
SH
46#include <linux/io.h>
47#include <linux/irq.h>
196719ec 48#include <linux/clk.h>
ead73183 49#include <linux/platform_device.h>
e6b043d5 50#include <linux/phy.h>
5eb32bd0 51#include <linux/fec.h>
ca2cc333
SG
52#include <linux/of.h>
53#include <linux/of_device.h>
54#include <linux/of_gpio.h>
55#include <linux/of_net.h>
5fa9c0fe 56#include <linux/regulator/consumer.h>
1da177e4 57
080853af 58#include <asm/cacheflush.h>
196719ec 59
1da177e4 60#include "fec.h"
1da177e4 61
085e79ed 62#if defined(CONFIG_ARM)
196719ec
SH
63#define FEC_ALIGNMENT 0xf
64#else
65#define FEC_ALIGNMENT 0x3
66#endif
67
b5680e0b 68#define DRIVER_NAME "fec"
dc975382 69#define FEC_NAPI_WEIGHT 64
b5680e0b 70
baa70a5c
FL
71/* Pause frame feild and FIFO threshold */
72#define FEC_ENET_FCE (1 << 5)
73#define FEC_ENET_RSEM_V 0x84
74#define FEC_ENET_RSFL_V 16
75#define FEC_ENET_RAEM_V 0x8
76#define FEC_ENET_RAFL_V 0x8
77#define FEC_ENET_OPD_V 0xFFF0
78
b5680e0b
SG
79/* Controller is ENET-MAC */
80#define FEC_QUIRK_ENET_MAC (1 << 0)
81/* Controller needs driver to swap frame */
82#define FEC_QUIRK_SWAP_FRAME (1 << 1)
0ca1e290
SG
83/* Controller uses gasket */
84#define FEC_QUIRK_USE_GASKET (1 << 2)
230dec61
SG
85/* Controller has GBIT support */
86#define FEC_QUIRK_HAS_GBIT (1 << 3)
ff43da86
FL
87/* Controller has extend desc buffer */
88#define FEC_QUIRK_HAS_BUFDESC_EX (1 << 4)
48496255
SG
89/* Controller has hardware checksum support */
90#define FEC_QUIRK_HAS_CSUM (1 << 5)
b5680e0b
SG
91
92static struct platform_device_id fec_devtype[] = {
93 {
0ca1e290 94 /* keep it for coldfire */
b5680e0b
SG
95 .name = DRIVER_NAME,
96 .driver_data = 0,
0ca1e290
SG
97 }, {
98 .name = "imx25-fec",
99 .driver_data = FEC_QUIRK_USE_GASKET,
100 }, {
101 .name = "imx27-fec",
102 .driver_data = 0,
b5680e0b
SG
103 }, {
104 .name = "imx28-fec",
105 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME,
230dec61
SG
106 }, {
107 .name = "imx6q-fec",
ff43da86 108 .driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
48496255 109 FEC_QUIRK_HAS_BUFDESC_EX | FEC_QUIRK_HAS_CSUM,
ca7c4a45 110 }, {
36803542 111 .name = "mvf600-fec",
ca7c4a45 112 .driver_data = FEC_QUIRK_ENET_MAC,
0ca1e290
SG
113 }, {
114 /* sentinel */
115 }
b5680e0b 116};
0ca1e290 117MODULE_DEVICE_TABLE(platform, fec_devtype);
b5680e0b 118
ca2cc333 119enum imx_fec_type {
a7dd3219 120 IMX25_FEC = 1, /* runs on i.mx25/50/53 */
ca2cc333
SG
121 IMX27_FEC, /* runs on i.mx27/35/51 */
122 IMX28_FEC,
230dec61 123 IMX6Q_FEC,
36803542 124 MVF600_FEC,
ca2cc333
SG
125};
126
127static const struct of_device_id fec_dt_ids[] = {
128 { .compatible = "fsl,imx25-fec", .data = &fec_devtype[IMX25_FEC], },
129 { .compatible = "fsl,imx27-fec", .data = &fec_devtype[IMX27_FEC], },
130 { .compatible = "fsl,imx28-fec", .data = &fec_devtype[IMX28_FEC], },
230dec61 131 { .compatible = "fsl,imx6q-fec", .data = &fec_devtype[IMX6Q_FEC], },
36803542 132 { .compatible = "fsl,mvf600-fec", .data = &fec_devtype[MVF600_FEC], },
ca2cc333
SG
133 { /* sentinel */ }
134};
135MODULE_DEVICE_TABLE(of, fec_dt_ids);
136
49da97dc
SG
137static unsigned char macaddr[ETH_ALEN];
138module_param_array(macaddr, byte, NULL, 0);
139MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
1da177e4 140
49da97dc 141#if defined(CONFIG_M5272)
1da177e4
LT
142/*
143 * Some hardware gets it MAC address out of local flash memory.
144 * if this is non-zero then assume it is the address to get MAC from.
145 */
146#if defined(CONFIG_NETtel)
147#define FEC_FLASHMAC 0xf0006006
148#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
149#define FEC_FLASHMAC 0xf0006000
1da177e4
LT
150#elif defined(CONFIG_CANCam)
151#define FEC_FLASHMAC 0xf0020000
7dd6a2aa
GU
152#elif defined (CONFIG_M5272C3)
153#define FEC_FLASHMAC (0xffe04000 + 4)
154#elif defined(CONFIG_MOD5272)
a7dd3219 155#define FEC_FLASHMAC 0xffc0406b
1da177e4
LT
156#else
157#define FEC_FLASHMAC 0
158#endif
43be6366 159#endif /* CONFIG_M5272 */
ead73183 160
ff43da86 161#if (((RX_RING_SIZE + TX_RING_SIZE) * 32) > PAGE_SIZE)
6b265293 162#error "FEC: descriptor ring size constants too large"
562d2f8c
GU
163#endif
164
22f6b860 165/* Interrupt events/masks. */
1da177e4
LT
166#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
167#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
168#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
169#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
170#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
171#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
172#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
173#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
174#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
175#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
176
4bee1f9a 177#define FEC_DEFAULT_IMASK (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII)
dc975382 178#define FEC_RX_DISABLED_IMASK (FEC_DEFAULT_IMASK & (~FEC_ENET_RXF))
4bee1f9a 179
1da177e4
LT
180/* The FEC stores dest/src/type, data, and checksum for receive packets.
181 */
182#define PKT_MAXBUF_SIZE 1518
183#define PKT_MINBUF_SIZE 64
184#define PKT_MAXBLR_SIZE 1520
185
4c09eed9
JB
186/* FEC receive acceleration */
187#define FEC_RACC_IPDIS (1 << 1)
188#define FEC_RACC_PRODIS (1 << 2)
189#define FEC_RACC_OPTIONS (FEC_RACC_IPDIS | FEC_RACC_PRODIS)
190
1da177e4 191/*
6b265293 192 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
1da177e4
LT
193 * size bits. Other FEC hardware does not, so we need to take that into
194 * account when setting it.
195 */
562d2f8c 196#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
085e79ed 197 defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARM)
1da177e4
LT
198#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
199#else
200#define OPT_FRAME_SIZE 0
201#endif
202
e6b043d5
BW
203/* FEC MII MMFR bits definition */
204#define FEC_MMFR_ST (1 << 30)
205#define FEC_MMFR_OP_READ (2 << 28)
206#define FEC_MMFR_OP_WRITE (1 << 28)
207#define FEC_MMFR_PA(v) ((v & 0x1f) << 23)
208#define FEC_MMFR_RA(v) ((v & 0x1f) << 18)
209#define FEC_MMFR_TA (2 << 16)
210#define FEC_MMFR_DATA(v) (v & 0xffff)
1da177e4 211
c3b084c2 212#define FEC_MII_TIMEOUT 30000 /* us */
1da177e4 213
22f6b860
SH
214/* Transmitter timeout */
215#define TX_TIMEOUT (2 * HZ)
1da177e4 216
baa70a5c
FL
217#define FEC_PAUSE_FLAG_AUTONEG 0x1
218#define FEC_PAUSE_FLAG_ENABLE 0x2
219
e163cc97
LW
220static int mii_cnt;
221
ff43da86
FL
222static struct bufdesc *fec_enet_get_nextdesc(struct bufdesc *bdp, int is_ex)
223{
224 struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
225 if (is_ex)
226 return (struct bufdesc *)(ex + 1);
227 else
228 return bdp + 1;
229}
230
231static struct bufdesc *fec_enet_get_prevdesc(struct bufdesc *bdp, int is_ex)
232{
233 struct bufdesc_ex *ex = (struct bufdesc_ex *)bdp;
234 if (is_ex)
235 return (struct bufdesc *)(ex - 1);
236 else
237 return bdp - 1;
238}
239
b5680e0b
SG
240static void *swap_buffer(void *bufaddr, int len)
241{
242 int i;
243 unsigned int *buf = bufaddr;
244
ffed61e6 245 for (i = 0; i < DIV_ROUND_UP(len, 4); i++, buf++)
b5680e0b
SG
246 *buf = cpu_to_be32(*buf);
247
248 return bufaddr;
249}
250
4c09eed9
JB
251static int
252fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)
253{
254 /* Only run for packets requiring a checksum. */
255 if (skb->ip_summed != CHECKSUM_PARTIAL)
256 return 0;
257
258 if (unlikely(skb_cow_head(skb, 0)))
259 return -1;
260
261 *(__sum16 *)(skb->head + skb->csum_start + skb->csum_offset) = 0;
262
263 return 0;
264}
265
c7621cb3 266static netdev_tx_t
c556167f 267fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1da177e4 268{
c556167f 269 struct fec_enet_private *fep = netdev_priv(ndev);
b5680e0b
SG
270 const struct platform_device_id *id_entry =
271 platform_get_device_id(fep->pdev);
2e28532f 272 struct bufdesc *bdp;
9555b31e 273 void *bufaddr;
0e702ab3 274 unsigned short status;
de5fb0a0 275 unsigned int index;
1da177e4 276
1da177e4 277 if (!fep->link) {
4c09eed9 278 /* Link is down or auto-negotiation is in progress. */
5b548140 279 return NETDEV_TX_BUSY;
1da177e4
LT
280 }
281
282 /* Fill in a Tx ring entry */
283 bdp = fep->cur_tx;
284
0e702ab3 285 status = bdp->cbd_sc;
22f6b860 286
0e702ab3 287 if (status & BD_ENET_TX_READY) {
1da177e4 288 /* Ooops. All transmit buffers are full. Bail out.
c556167f 289 * This should not happen, since ndev->tbusy should be set.
1da177e4 290 */
31b7720c 291 netdev_err(ndev, "tx queue full!\n");
5b548140 292 return NETDEV_TX_BUSY;
1da177e4 293 }
1da177e4 294
4c09eed9
JB
295 /* Protocol checksum off-load for TCP and UDP. */
296 if (fec_enet_clear_csum(skb, ndev)) {
297 kfree_skb(skb);
298 return NETDEV_TX_OK;
299 }
300
22f6b860 301 /* Clear all of the status flags */
0e702ab3 302 status &= ~BD_ENET_TX_STATS;
1da177e4 303
22f6b860 304 /* Set buffer length and buffer pointer */
9555b31e 305 bufaddr = skb->data;
1da177e4
LT
306 bdp->cbd_datlen = skb->len;
307
308 /*
22f6b860
SH
309 * On some FEC implementations data must be aligned on
310 * 4-byte boundaries. Use bounce buffers to copy data
311 * and get it aligned. Ugh.
1da177e4 312 */
de5fb0a0
FL
313 if (fep->bufdesc_ex)
314 index = (struct bufdesc_ex *)bdp -
315 (struct bufdesc_ex *)fep->tx_bd_base;
316 else
317 index = bdp - fep->tx_bd_base;
318
9555b31e 319 if (((unsigned long) bufaddr) & FEC_ALIGNMENT) {
8a73b0bc 320 memcpy(fep->tx_bounce[index], skb->data, skb->len);
9555b31e 321 bufaddr = fep->tx_bounce[index];
1da177e4
LT
322 }
323
b5680e0b
SG
324 /*
325 * Some design made an incorrect assumption on endian mode of
326 * the system that it's running on. As the result, driver has to
327 * swap every frame going to and coming from the controller.
328 */
329 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
330 swap_buffer(bufaddr, skb->len);
331
22f6b860 332 /* Save skb pointer */
de5fb0a0 333 fep->tx_skbuff[index] = skb;
6aa20a22 334
1da177e4
LT
335 /* Push the data cache so the CPM does not get stale memory
336 * data.
337 */
d1ab1f54 338 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
f0b3fbea 339 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
1da177e4 340
0e702ab3
GU
341 /* Send it on its way. Tell FEC it's ready, interrupt when done,
342 * it's the last BD of the frame, and to put the CRC on the end.
1da177e4 343 */
0e702ab3 344 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
1da177e4 345 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
0e702ab3 346 bdp->cbd_sc = status;
1da177e4 347
ff43da86
FL
348 if (fep->bufdesc_ex) {
349
350 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
351 ebdp->cbd_bdu = 0;
352 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
6605b730 353 fep->hwts_tx_en)) {
ff43da86 354 ebdp->cbd_esc = (BD_ENET_TX_TS | BD_ENET_TX_INT);
6605b730 355 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
ff43da86 356 } else {
ff43da86 357 ebdp->cbd_esc = BD_ENET_TX_INT;
4c09eed9
JB
358
359 /* Enable protocol checksum flags
360 * We do not bother with the IP Checksum bits as they
361 * are done by the kernel
362 */
363 if (skb->ip_summed == CHECKSUM_PARTIAL)
364 ebdp->cbd_esc |= BD_ENET_TX_PINS;
ff43da86 365 }
6605b730 366 }
22f6b860
SH
367 /* If this was the last BD in the ring, start at the beginning again. */
368 if (status & BD_ENET_TX_WRAP)
1da177e4 369 bdp = fep->tx_bd_base;
22f6b860 370 else
ff43da86 371 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
1da177e4 372
de5fb0a0
FL
373 fep->cur_tx = bdp;
374
375 if (fep->cur_tx == fep->dirty_tx)
c556167f 376 netif_stop_queue(ndev);
1da177e4 377
de5fb0a0
FL
378 /* Trigger transmission start */
379 writel(0, fep->hwp + FEC_X_DES_ACTIVE);
1da177e4 380
18a03b97
RC
381 skb_tx_timestamp(skb);
382
6ed10654 383 return NETDEV_TX_OK;
1da177e4
LT
384}
385
14109a59
FL
386/* Init RX & TX buffer descriptors
387 */
388static void fec_enet_bd_init(struct net_device *dev)
389{
390 struct fec_enet_private *fep = netdev_priv(dev);
391 struct bufdesc *bdp;
392 unsigned int i;
393
394 /* Initialize the receive buffer descriptors. */
395 bdp = fep->rx_bd_base;
396 for (i = 0; i < RX_RING_SIZE; i++) {
397
398 /* Initialize the BD for every fragment in the page. */
399 if (bdp->cbd_bufaddr)
400 bdp->cbd_sc = BD_ENET_RX_EMPTY;
401 else
402 bdp->cbd_sc = 0;
403 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
404 }
405
406 /* Set the last buffer to wrap */
407 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
408 bdp->cbd_sc |= BD_SC_WRAP;
409
410 fep->cur_rx = fep->rx_bd_base;
411
412 /* ...and the same for transmit */
413 bdp = fep->tx_bd_base;
414 fep->cur_tx = bdp;
415 for (i = 0; i < TX_RING_SIZE; i++) {
416
417 /* Initialize the BD for every fragment in the page. */
418 bdp->cbd_sc = 0;
419 if (bdp->cbd_bufaddr && fep->tx_skbuff[i]) {
420 dev_kfree_skb_any(fep->tx_skbuff[i]);
421 fep->tx_skbuff[i] = NULL;
422 }
423 bdp->cbd_bufaddr = 0;
424 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
425 }
426
427 /* Set the last buffer to wrap */
428 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
429 bdp->cbd_sc |= BD_SC_WRAP;
430 fep->dirty_tx = bdp;
431}
432
45993653
UKK
433/* This function is called to start or restart the FEC during a link
434 * change. This only happens when switching between half and full
435 * duplex.
436 */
1da177e4 437static void
45993653 438fec_restart(struct net_device *ndev, int duplex)
1da177e4 439{
c556167f 440 struct fec_enet_private *fep = netdev_priv(ndev);
45993653
UKK
441 const struct platform_device_id *id_entry =
442 platform_get_device_id(fep->pdev);
443 int i;
4c09eed9 444 u32 val;
cd1f402c
UKK
445 u32 temp_mac[2];
446 u32 rcntl = OPT_FRAME_SIZE | 0x04;
230dec61 447 u32 ecntl = 0x2; /* ETHEREN */
1da177e4 448
54309fa6
FL
449 if (netif_running(ndev)) {
450 netif_device_detach(ndev);
451 napi_disable(&fep->napi);
452 netif_stop_queue(ndev);
31691344 453 netif_tx_lock_bh(ndev);
54309fa6
FL
454 }
455
45993653
UKK
456 /* Whack a reset. We should wait for this. */
457 writel(1, fep->hwp + FEC_ECNTRL);
458 udelay(10);
1da177e4 459
45993653
UKK
460 /*
461 * enet-mac reset will reset mac address registers too,
462 * so need to reconfigure it.
463 */
464 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
465 memcpy(&temp_mac, ndev->dev_addr, ETH_ALEN);
466 writel(cpu_to_be32(temp_mac[0]), fep->hwp + FEC_ADDR_LOW);
467 writel(cpu_to_be32(temp_mac[1]), fep->hwp + FEC_ADDR_HIGH);
468 }
1da177e4 469
45993653
UKK
470 /* Clear any outstanding interrupt. */
471 writel(0xffc00000, fep->hwp + FEC_IEVENT);
1da177e4 472
45993653
UKK
473 /* Reset all multicast. */
474 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
475 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
476#ifndef CONFIG_M5272
477 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
478 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
479#endif
1da177e4 480
45993653
UKK
481 /* Set maximum receive buffer size. */
482 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
1da177e4 483
14109a59
FL
484 fec_enet_bd_init(ndev);
485
45993653
UKK
486 /* Set receive and transmit descriptor base. */
487 writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
ff43da86
FL
488 if (fep->bufdesc_ex)
489 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc_ex)
490 * RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
491 else
492 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc)
493 * RX_RING_SIZE, fep->hwp + FEC_X_DES_START);
45993653 494
45993653 495
45993653
UKK
496 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
497 if (fep->tx_skbuff[i]) {
498 dev_kfree_skb_any(fep->tx_skbuff[i]);
499 fep->tx_skbuff[i] = NULL;
1da177e4 500 }
45993653 501 }
97b72e43 502
45993653
UKK
503 /* Enable MII mode */
504 if (duplex) {
cd1f402c 505 /* FD enable */
45993653
UKK
506 writel(0x04, fep->hwp + FEC_X_CNTRL);
507 } else {
cd1f402c
UKK
508 /* No Rcv on Xmit */
509 rcntl |= 0x02;
45993653
UKK
510 writel(0x0, fep->hwp + FEC_X_CNTRL);
511 }
cd1f402c 512
45993653
UKK
513 fep->full_duplex = duplex;
514
515 /* Set MII speed */
516 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
517
4c09eed9
JB
518 /* set RX checksum */
519 val = readl(fep->hwp + FEC_RACC);
520 if (fep->csum_flags & FLAG_RX_CSUM_ENABLED)
521 val |= FEC_RACC_OPTIONS;
522 else
523 val &= ~FEC_RACC_OPTIONS;
524 writel(val, fep->hwp + FEC_RACC);
525
45993653
UKK
526 /*
527 * The phy interface and speed need to get configured
528 * differently on enet-mac.
529 */
530 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
cd1f402c
UKK
531 /* Enable flow control and length check */
532 rcntl |= 0x40000000 | 0x00000020;
45993653 533
230dec61
SG
534 /* RGMII, RMII or MII */
535 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII)
536 rcntl |= (1 << 6);
537 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
cd1f402c 538 rcntl |= (1 << 8);
45993653 539 else
cd1f402c 540 rcntl &= ~(1 << 8);
45993653 541
230dec61
SG
542 /* 1G, 100M or 10M */
543 if (fep->phy_dev) {
544 if (fep->phy_dev->speed == SPEED_1000)
545 ecntl |= (1 << 5);
546 else if (fep->phy_dev->speed == SPEED_100)
547 rcntl &= ~(1 << 9);
548 else
549 rcntl |= (1 << 9);
550 }
45993653
UKK
551 } else {
552#ifdef FEC_MIIGSK_ENR
0ca1e290 553 if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
8d82f219 554 u32 cfgr;
45993653
UKK
555 /* disable the gasket and wait */
556 writel(0, fep->hwp + FEC_MIIGSK_ENR);
557 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
558 udelay(1);
559
560 /*
561 * configure the gasket:
562 * RMII, 50 MHz, no loopback, no echo
0ca1e290 563 * MII, 25 MHz, no loopback, no echo
45993653 564 */
8d82f219
EB
565 cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
566 ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
567 if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
568 cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
569 writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
45993653
UKK
570
571 /* re-enable the gasket */
572 writel(2, fep->hwp + FEC_MIIGSK_ENR);
97b72e43 573 }
45993653
UKK
574#endif
575 }
baa70a5c
FL
576
577 /* enable pause frame*/
578 if ((fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) ||
579 ((fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) &&
580 fep->phy_dev && fep->phy_dev->pause)) {
581 rcntl |= FEC_ENET_FCE;
582
4c09eed9 583 /* set FIFO threshold parameter to reduce overrun */
baa70a5c
FL
584 writel(FEC_ENET_RSEM_V, fep->hwp + FEC_R_FIFO_RSEM);
585 writel(FEC_ENET_RSFL_V, fep->hwp + FEC_R_FIFO_RSFL);
586 writel(FEC_ENET_RAEM_V, fep->hwp + FEC_R_FIFO_RAEM);
587 writel(FEC_ENET_RAFL_V, fep->hwp + FEC_R_FIFO_RAFL);
588
589 /* OPD */
590 writel(FEC_ENET_OPD_V, fep->hwp + FEC_OPD);
591 } else {
592 rcntl &= ~FEC_ENET_FCE;
593 }
594
cd1f402c 595 writel(rcntl, fep->hwp + FEC_R_CNTRL);
3b2b74ca 596
230dec61
SG
597 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
598 /* enable ENET endian swap */
599 ecntl |= (1 << 8);
600 /* enable ENET store and forward mode */
601 writel(1 << 8, fep->hwp + FEC_X_WMRK);
602 }
603
ff43da86
FL
604 if (fep->bufdesc_ex)
605 ecntl |= (1 << 4);
6605b730 606
45993653 607 /* And last, enable the transmit and receive processing */
230dec61 608 writel(ecntl, fep->hwp + FEC_ECNTRL);
45993653
UKK
609 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
610
ff43da86
FL
611 if (fep->bufdesc_ex)
612 fec_ptp_start_cyclecounter(ndev);
613
45993653
UKK
614 /* Enable interrupts we wish to service */
615 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
54309fa6
FL
616
617 if (netif_running(ndev)) {
31691344 618 netif_tx_unlock_bh(ndev);
54309fa6 619 netif_wake_queue(ndev);
1ed0d56c
FE
620 napi_enable(&fep->napi);
621 netif_device_attach(ndev);
54309fa6 622 }
45993653
UKK
623}
624
625static void
626fec_stop(struct net_device *ndev)
627{
628 struct fec_enet_private *fep = netdev_priv(ndev);
230dec61
SG
629 const struct platform_device_id *id_entry =
630 platform_get_device_id(fep->pdev);
42431dc2 631 u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
45993653
UKK
632
633 /* We cannot expect a graceful transmit stop without link !!! */
634 if (fep->link) {
635 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
636 udelay(10);
637 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
31b7720c 638 netdev_err(ndev, "Graceful transmit stop did not complete!\n");
45993653
UKK
639 }
640
641 /* Whack a reset. We should wait for this. */
642 writel(1, fep->hwp + FEC_ECNTRL);
643 udelay(10);
644 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
645 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
230dec61
SG
646
647 /* We have to keep ENET enabled to have MII interrupt stay working */
42431dc2 648 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
230dec61 649 writel(2, fep->hwp + FEC_ECNTRL);
42431dc2
LW
650 writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
651 }
1da177e4
LT
652}
653
654
45993653
UKK
655static void
656fec_timeout(struct net_device *ndev)
657{
658 struct fec_enet_private *fep = netdev_priv(ndev);
659
660 ndev->stats.tx_errors++;
661
54309fa6
FL
662 fep->delay_work.timeout = true;
663 schedule_delayed_work(&(fep->delay_work.delay_work), 0);
664}
665
666static void fec_enet_work(struct work_struct *work)
667{
668 struct fec_enet_private *fep =
669 container_of(work,
670 struct fec_enet_private,
671 delay_work.delay_work.work);
672
673 if (fep->delay_work.timeout) {
674 fep->delay_work.timeout = false;
675 fec_restart(fep->netdev, fep->full_duplex);
676 netif_wake_queue(fep->netdev);
677 }
45993653
UKK
678}
679
1da177e4 680static void
c556167f 681fec_enet_tx(struct net_device *ndev)
1da177e4
LT
682{
683 struct fec_enet_private *fep;
2e28532f 684 struct bufdesc *bdp;
0e702ab3 685 unsigned short status;
1da177e4 686 struct sk_buff *skb;
de5fb0a0 687 int index = 0;
1da177e4 688
c556167f 689 fep = netdev_priv(ndev);
1da177e4
LT
690 bdp = fep->dirty_tx;
691
de5fb0a0
FL
692 /* get next bdp of dirty_tx */
693 if (bdp->cbd_sc & BD_ENET_TX_WRAP)
694 bdp = fep->tx_bd_base;
695 else
696 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
697
0e702ab3 698 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
de5fb0a0
FL
699
700 /* current queue is empty */
701 if (bdp == fep->cur_tx)
f0b3fbea
SH
702 break;
703
de5fb0a0
FL
704 if (fep->bufdesc_ex)
705 index = (struct bufdesc_ex *)bdp -
706 (struct bufdesc_ex *)fep->tx_bd_base;
707 else
708 index = bdp - fep->tx_bd_base;
709
d1ab1f54
UKK
710 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
711 FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
f0b3fbea 712 bdp->cbd_bufaddr = 0;
1da177e4 713
de5fb0a0
FL
714 skb = fep->tx_skbuff[index];
715
1da177e4 716 /* Check for errors. */
0e702ab3 717 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
1da177e4
LT
718 BD_ENET_TX_RL | BD_ENET_TX_UN |
719 BD_ENET_TX_CSL)) {
c556167f 720 ndev->stats.tx_errors++;
0e702ab3 721 if (status & BD_ENET_TX_HB) /* No heartbeat */
c556167f 722 ndev->stats.tx_heartbeat_errors++;
0e702ab3 723 if (status & BD_ENET_TX_LC) /* Late collision */
c556167f 724 ndev->stats.tx_window_errors++;
0e702ab3 725 if (status & BD_ENET_TX_RL) /* Retrans limit */
c556167f 726 ndev->stats.tx_aborted_errors++;
0e702ab3 727 if (status & BD_ENET_TX_UN) /* Underrun */
c556167f 728 ndev->stats.tx_fifo_errors++;
0e702ab3 729 if (status & BD_ENET_TX_CSL) /* Carrier lost */
c556167f 730 ndev->stats.tx_carrier_errors++;
1da177e4 731 } else {
c556167f 732 ndev->stats.tx_packets++;
1da177e4
LT
733 }
734
ff43da86
FL
735 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
736 fep->bufdesc_ex) {
6605b730
FL
737 struct skb_shared_hwtstamps shhwtstamps;
738 unsigned long flags;
ff43da86 739 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
6605b730
FL
740
741 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
742 spin_lock_irqsave(&fep->tmreg_lock, flags);
743 shhwtstamps.hwtstamp = ns_to_ktime(
ff43da86 744 timecounter_cyc2time(&fep->tc, ebdp->ts));
6605b730
FL
745 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
746 skb_tstamp_tx(skb, &shhwtstamps);
747 }
ff43da86 748
0e702ab3 749 if (status & BD_ENET_TX_READY)
31b7720c 750 netdev_err(ndev, "HEY! Enet xmit interrupt and TX_READY\n");
22f6b860 751
1da177e4
LT
752 /* Deferred means some collisions occurred during transmit,
753 * but we eventually sent the packet OK.
754 */
0e702ab3 755 if (status & BD_ENET_TX_DEF)
c556167f 756 ndev->stats.collisions++;
6aa20a22 757
22f6b860 758 /* Free the sk buffer associated with this last transmit */
1da177e4 759 dev_kfree_skb_any(skb);
de5fb0a0
FL
760 fep->tx_skbuff[index] = NULL;
761
762 fep->dirty_tx = bdp;
6aa20a22 763
22f6b860 764 /* Update pointer to next buffer descriptor to be transmitted */
0e702ab3 765 if (status & BD_ENET_TX_WRAP)
1da177e4
LT
766 bdp = fep->tx_bd_base;
767 else
ff43da86 768 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
6aa20a22 769
22f6b860 770 /* Since we have freed up a buffer, the ring is no longer full
1da177e4 771 */
de5fb0a0 772 if (fep->dirty_tx != fep->cur_tx) {
c556167f
UKK
773 if (netif_queue_stopped(ndev))
774 netif_wake_queue(ndev);
1da177e4
LT
775 }
776 }
de5fb0a0 777 return;
1da177e4
LT
778}
779
780
781/* During a receive, the cur_rx points to the current incoming buffer.
782 * When we update through the ring, if the next incoming buffer has
783 * not been given to the system, we just set the empty indicator,
784 * effectively tossing the packet.
785 */
dc975382
FL
786static int
787fec_enet_rx(struct net_device *ndev, int budget)
1da177e4 788{
c556167f 789 struct fec_enet_private *fep = netdev_priv(ndev);
b5680e0b
SG
790 const struct platform_device_id *id_entry =
791 platform_get_device_id(fep->pdev);
2e28532f 792 struct bufdesc *bdp;
0e702ab3 793 unsigned short status;
1da177e4
LT
794 struct sk_buff *skb;
795 ushort pkt_len;
796 __u8 *data;
dc975382 797 int pkt_received = 0;
6aa20a22 798
0e702ab3
GU
799#ifdef CONFIG_M532x
800 flush_cache_all();
6aa20a22 801#endif
1da177e4 802
1da177e4
LT
803 /* First, grab all of the stats for the incoming packet.
804 * These get messed up if we get called due to a busy condition.
805 */
806 bdp = fep->cur_rx;
807
22f6b860 808 while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
1da177e4 809
dc975382
FL
810 if (pkt_received >= budget)
811 break;
812 pkt_received++;
813
22f6b860
SH
814 /* Since we have allocated space to hold a complete frame,
815 * the last indicator should be set.
816 */
817 if ((status & BD_ENET_RX_LAST) == 0)
31b7720c 818 netdev_err(ndev, "rcv is not +last\n");
1da177e4 819
22f6b860
SH
820 if (!fep->opened)
821 goto rx_processing_done;
1da177e4 822
22f6b860
SH
823 /* Check for errors. */
824 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
1da177e4 825 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
c556167f 826 ndev->stats.rx_errors++;
22f6b860
SH
827 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
828 /* Frame too long or too short. */
c556167f 829 ndev->stats.rx_length_errors++;
22f6b860
SH
830 }
831 if (status & BD_ENET_RX_NO) /* Frame alignment */
c556167f 832 ndev->stats.rx_frame_errors++;
22f6b860 833 if (status & BD_ENET_RX_CR) /* CRC Error */
c556167f 834 ndev->stats.rx_crc_errors++;
22f6b860 835 if (status & BD_ENET_RX_OV) /* FIFO overrun */
c556167f 836 ndev->stats.rx_fifo_errors++;
1da177e4 837 }
1da177e4 838
22f6b860
SH
839 /* Report late collisions as a frame error.
840 * On this error, the BD is closed, but we don't know what we
841 * have in the buffer. So, just drop this frame on the floor.
842 */
843 if (status & BD_ENET_RX_CL) {
c556167f
UKK
844 ndev->stats.rx_errors++;
845 ndev->stats.rx_frame_errors++;
22f6b860
SH
846 goto rx_processing_done;
847 }
1da177e4 848
22f6b860 849 /* Process the incoming frame. */
c556167f 850 ndev->stats.rx_packets++;
22f6b860 851 pkt_len = bdp->cbd_datlen;
c556167f 852 ndev->stats.rx_bytes += pkt_len;
22f6b860 853 data = (__u8*)__va(bdp->cbd_bufaddr);
1da177e4 854
d1ab1f54
UKK
855 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
856 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
ccdc4f19 857
b5680e0b
SG
858 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
859 swap_buffer(data, pkt_len);
860
22f6b860
SH
861 /* This does 16 byte alignment, exactly what we need.
862 * The packet length includes FCS, but we don't want to
863 * include that when passing upstream as it messes up
864 * bridging applications.
865 */
b72061a3 866 skb = netdev_alloc_skb(ndev, pkt_len - 4 + NET_IP_ALIGN);
1da177e4 867
8549889c 868 if (unlikely(!skb)) {
c556167f 869 ndev->stats.rx_dropped++;
22f6b860 870 } else {
8549889c 871 skb_reserve(skb, NET_IP_ALIGN);
22f6b860
SH
872 skb_put(skb, pkt_len - 4); /* Make room */
873 skb_copy_to_linear_data(skb, data, pkt_len - 4);
c556167f 874 skb->protocol = eth_type_trans(skb, ndev);
ff43da86 875
6605b730 876 /* Get receive timestamp from the skb */
ff43da86 877 if (fep->hwts_rx_en && fep->bufdesc_ex) {
6605b730
FL
878 struct skb_shared_hwtstamps *shhwtstamps =
879 skb_hwtstamps(skb);
880 unsigned long flags;
ff43da86
FL
881 struct bufdesc_ex *ebdp =
882 (struct bufdesc_ex *)bdp;
6605b730
FL
883
884 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
885
886 spin_lock_irqsave(&fep->tmreg_lock, flags);
887 shhwtstamps->hwtstamp = ns_to_ktime(
ff43da86 888 timecounter_cyc2time(&fep->tc, ebdp->ts));
6605b730
FL
889 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
890 }
ff43da86 891
4c09eed9
JB
892 if (fep->bufdesc_ex &&
893 (fep->csum_flags & FLAG_RX_CSUM_ENABLED)) {
894 struct bufdesc_ex *ebdp =
895 (struct bufdesc_ex *)bdp;
896 if (!(ebdp->cbd_esc & FLAG_RX_CSUM_ERROR)) {
897 /* don't check it */
898 skb->ip_summed = CHECKSUM_UNNECESSARY;
899 } else {
900 skb_checksum_none_assert(skb);
901 }
902 }
903
18a03b97 904 if (!skb_defer_rx_timestamp(skb))
dc975382 905 napi_gro_receive(&fep->napi, skb);
22f6b860 906 }
f0b3fbea 907
d1ab1f54
UKK
908 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
909 FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
22f6b860
SH
910rx_processing_done:
911 /* Clear the status flags for this buffer */
912 status &= ~BD_ENET_RX_STATS;
1da177e4 913
22f6b860
SH
914 /* Mark the buffer empty */
915 status |= BD_ENET_RX_EMPTY;
916 bdp->cbd_sc = status;
6aa20a22 917
ff43da86
FL
918 if (fep->bufdesc_ex) {
919 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
920
921 ebdp->cbd_esc = BD_ENET_RX_INT;
922 ebdp->cbd_prot = 0;
923 ebdp->cbd_bdu = 0;
924 }
6605b730 925
22f6b860
SH
926 /* Update BD pointer to next entry */
927 if (status & BD_ENET_RX_WRAP)
928 bdp = fep->rx_bd_base;
929 else
ff43da86 930 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
22f6b860
SH
931 /* Doing this here will keep the FEC running while we process
932 * incoming frames. On a heavily loaded network, we should be
933 * able to keep up at the expense of system resources.
934 */
935 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
936 }
2e28532f 937 fep->cur_rx = bdp;
1da177e4 938
dc975382 939 return pkt_received;
1da177e4
LT
940}
941
45993653
UKK
942static irqreturn_t
943fec_enet_interrupt(int irq, void *dev_id)
944{
945 struct net_device *ndev = dev_id;
946 struct fec_enet_private *fep = netdev_priv(ndev);
947 uint int_events;
948 irqreturn_t ret = IRQ_NONE;
949
950 do {
951 int_events = readl(fep->hwp + FEC_IEVENT);
952 writel(int_events, fep->hwp + FEC_IEVENT);
953
de5fb0a0 954 if (int_events & (FEC_ENET_RXF | FEC_ENET_TXF)) {
45993653 955 ret = IRQ_HANDLED;
dc975382
FL
956
957 /* Disable the RX interrupt */
958 if (napi_schedule_prep(&fep->napi)) {
959 writel(FEC_RX_DISABLED_IMASK,
960 fep->hwp + FEC_IMASK);
961 __napi_schedule(&fep->napi);
962 }
45993653
UKK
963 }
964
45993653
UKK
965 if (int_events & FEC_ENET_MII) {
966 ret = IRQ_HANDLED;
967 complete(&fep->mdio_done);
968 }
969 } while (int_events);
970
971 return ret;
972}
973
dc975382
FL
974static int fec_enet_rx_napi(struct napi_struct *napi, int budget)
975{
976 struct net_device *ndev = napi->dev;
977 int pkts = fec_enet_rx(ndev, budget);
978 struct fec_enet_private *fep = netdev_priv(ndev);
45993653 979
de5fb0a0
FL
980 fec_enet_tx(ndev);
981
dc975382
FL
982 if (pkts < budget) {
983 napi_complete(napi);
984 writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
985 }
986 return pkts;
987}
45993653 988
e6b043d5 989/* ------------------------------------------------------------------------- */
0c7768a0 990static void fec_get_mac(struct net_device *ndev)
1da177e4 991{
c556167f 992 struct fec_enet_private *fep = netdev_priv(ndev);
49da97dc 993 struct fec_platform_data *pdata = fep->pdev->dev.platform_data;
e6b043d5 994 unsigned char *iap, tmpaddr[ETH_ALEN];
1da177e4 995
49da97dc
SG
996 /*
997 * try to get mac address in following order:
998 *
999 * 1) module parameter via kernel command line in form
1000 * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0
1001 */
1002 iap = macaddr;
1003
ca2cc333
SG
1004 /*
1005 * 2) from device tree data
1006 */
1007 if (!is_valid_ether_addr(iap)) {
1008 struct device_node *np = fep->pdev->dev.of_node;
1009 if (np) {
1010 const char *mac = of_get_mac_address(np);
1011 if (mac)
1012 iap = (unsigned char *) mac;
1013 }
1014 }
ca2cc333 1015
49da97dc 1016 /*
ca2cc333 1017 * 3) from flash or fuse (via platform data)
49da97dc
SG
1018 */
1019 if (!is_valid_ether_addr(iap)) {
1020#ifdef CONFIG_M5272
1021 if (FEC_FLASHMAC)
1022 iap = (unsigned char *)FEC_FLASHMAC;
1023#else
1024 if (pdata)
589efdc7 1025 iap = (unsigned char *)&pdata->mac;
49da97dc
SG
1026#endif
1027 }
1028
1029 /*
ca2cc333 1030 * 4) FEC mac registers set by bootloader
49da97dc
SG
1031 */
1032 if (!is_valid_ether_addr(iap)) {
1033 *((unsigned long *) &tmpaddr[0]) =
1034 be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW));
1035 *((unsigned short *) &tmpaddr[4]) =
1036 be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
e6b043d5 1037 iap = &tmpaddr[0];
1da177e4
LT
1038 }
1039
ff5b2fab
LS
1040 /*
1041 * 5) random mac address
1042 */
1043 if (!is_valid_ether_addr(iap)) {
1044 /* Report it and use a random ethernet address instead */
1045 netdev_err(ndev, "Invalid MAC address: %pM\n", iap);
1046 eth_hw_addr_random(ndev);
1047 netdev_info(ndev, "Using random MAC address: %pM\n",
1048 ndev->dev_addr);
1049 return;
1050 }
1051
c556167f 1052 memcpy(ndev->dev_addr, iap, ETH_ALEN);
1da177e4 1053
49da97dc
SG
1054 /* Adjust MAC if using macaddr */
1055 if (iap == macaddr)
43af940c 1056 ndev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->dev_id;
1da177e4
LT
1057}
1058
e6b043d5 1059/* ------------------------------------------------------------------------- */
1da177e4 1060
e6b043d5
BW
1061/*
1062 * Phy section
1063 */
c556167f 1064static void fec_enet_adjust_link(struct net_device *ndev)
1da177e4 1065{
c556167f 1066 struct fec_enet_private *fep = netdev_priv(ndev);
e6b043d5 1067 struct phy_device *phy_dev = fep->phy_dev;
e6b043d5 1068 int status_change = 0;
1da177e4 1069
e6b043d5
BW
1070 /* Prevent a state halted on mii error */
1071 if (fep->mii_timeout && phy_dev->state == PHY_HALTED) {
1072 phy_dev->state = PHY_RESUMING;
54309fa6 1073 return;
e6b043d5 1074 }
1da177e4 1075
e6b043d5 1076 if (phy_dev->link) {
d97e7497 1077 if (!fep->link) {
6ea0722f 1078 fep->link = phy_dev->link;
e6b043d5
BW
1079 status_change = 1;
1080 }
1da177e4 1081
d97e7497
LS
1082 if (fep->full_duplex != phy_dev->duplex)
1083 status_change = 1;
1084
1085 if (phy_dev->speed != fep->speed) {
1086 fep->speed = phy_dev->speed;
1087 status_change = 1;
1088 }
1089
1090 /* if any of the above changed restart the FEC */
1091 if (status_change)
c556167f 1092 fec_restart(ndev, phy_dev->duplex);
d97e7497
LS
1093 } else {
1094 if (fep->link) {
c556167f 1095 fec_stop(ndev);
8d7ed0f0 1096 fep->link = phy_dev->link;
d97e7497
LS
1097 status_change = 1;
1098 }
1da177e4 1099 }
6aa20a22 1100
e6b043d5
BW
1101 if (status_change)
1102 phy_print_status(phy_dev);
1103}
1da177e4 1104
e6b043d5 1105static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
1da177e4 1106{
e6b043d5 1107 struct fec_enet_private *fep = bus->priv;
97b72e43 1108 unsigned long time_left;
1da177e4 1109
e6b043d5 1110 fep->mii_timeout = 0;
97b72e43 1111 init_completion(&fep->mdio_done);
e6b043d5
BW
1112
1113 /* start a read op */
1114 writel(FEC_MMFR_ST | FEC_MMFR_OP_READ |
1115 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1116 FEC_MMFR_TA, fep->hwp + FEC_MII_DATA);
1117
1118 /* wait for end of transfer */
97b72e43
BS
1119 time_left = wait_for_completion_timeout(&fep->mdio_done,
1120 usecs_to_jiffies(FEC_MII_TIMEOUT));
1121 if (time_left == 0) {
1122 fep->mii_timeout = 1;
31b7720c 1123 netdev_err(fep->netdev, "MDIO read timeout\n");
97b72e43 1124 return -ETIMEDOUT;
1da177e4 1125 }
1da177e4 1126
e6b043d5
BW
1127 /* return value */
1128 return FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA));
7dd6a2aa 1129}
6aa20a22 1130
e6b043d5
BW
1131static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
1132 u16 value)
1da177e4 1133{
e6b043d5 1134 struct fec_enet_private *fep = bus->priv;
97b72e43 1135 unsigned long time_left;
1da177e4 1136
e6b043d5 1137 fep->mii_timeout = 0;
97b72e43 1138 init_completion(&fep->mdio_done);
1da177e4 1139
862f0982
SG
1140 /* start a write op */
1141 writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE |
e6b043d5
BW
1142 FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) |
1143 FEC_MMFR_TA | FEC_MMFR_DATA(value),
1144 fep->hwp + FEC_MII_DATA);
1145
1146 /* wait for end of transfer */
97b72e43
BS
1147 time_left = wait_for_completion_timeout(&fep->mdio_done,
1148 usecs_to_jiffies(FEC_MII_TIMEOUT));
1149 if (time_left == 0) {
1150 fep->mii_timeout = 1;
31b7720c 1151 netdev_err(fep->netdev, "MDIO write timeout\n");
97b72e43 1152 return -ETIMEDOUT;
e6b043d5 1153 }
1da177e4 1154
e6b043d5
BW
1155 return 0;
1156}
1da177e4 1157
e6b043d5 1158static int fec_enet_mdio_reset(struct mii_bus *bus)
1da177e4 1159{
e6b043d5 1160 return 0;
1da177e4
LT
1161}
1162
c556167f 1163static int fec_enet_mii_probe(struct net_device *ndev)
562d2f8c 1164{
c556167f 1165 struct fec_enet_private *fep = netdev_priv(ndev);
230dec61
SG
1166 const struct platform_device_id *id_entry =
1167 platform_get_device_id(fep->pdev);
e6b043d5 1168 struct phy_device *phy_dev = NULL;
6fcc040f
GU
1169 char mdio_bus_id[MII_BUS_ID_SIZE];
1170 char phy_name[MII_BUS_ID_SIZE + 3];
1171 int phy_id;
43af940c 1172 int dev_id = fep->dev_id;
562d2f8c 1173
418bd0d4
BW
1174 fep->phy_dev = NULL;
1175
6fcc040f
GU
1176 /* check for attached phy */
1177 for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
1178 if ((fep->mii_bus->phy_mask & (1 << phy_id)))
1179 continue;
1180 if (fep->mii_bus->phy_map[phy_id] == NULL)
1181 continue;
1182 if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
1183 continue;
b5680e0b
SG
1184 if (dev_id--)
1185 continue;
6fcc040f
GU
1186 strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
1187 break;
e6b043d5 1188 }
1da177e4 1189
6fcc040f 1190 if (phy_id >= PHY_MAX_ADDR) {
31b7720c 1191 netdev_info(ndev, "no PHY, assuming direct connection to switch\n");
ea51ade9 1192 strncpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE);
6fcc040f
GU
1193 phy_id = 0;
1194 }
1195
a7ed07d5 1196 snprintf(phy_name, sizeof(phy_name), PHY_ID_FMT, mdio_bus_id, phy_id);
f9a8f83b 1197 phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link,
230dec61 1198 fep->phy_interface);
6fcc040f 1199 if (IS_ERR(phy_dev)) {
31b7720c 1200 netdev_err(ndev, "could not attach to PHY\n");
6fcc040f 1201 return PTR_ERR(phy_dev);
e6b043d5 1202 }
1da177e4 1203
e6b043d5 1204 /* mask with MAC supported features */
baa70a5c 1205 if (id_entry->driver_data & FEC_QUIRK_HAS_GBIT) {
230dec61 1206 phy_dev->supported &= PHY_GBIT_FEATURES;
baa70a5c
FL
1207 phy_dev->supported |= SUPPORTED_Pause;
1208 }
230dec61
SG
1209 else
1210 phy_dev->supported &= PHY_BASIC_FEATURES;
1211
e6b043d5 1212 phy_dev->advertising = phy_dev->supported;
1da177e4 1213
e6b043d5
BW
1214 fep->phy_dev = phy_dev;
1215 fep->link = 0;
1216 fep->full_duplex = 0;
1da177e4 1217
31b7720c
JP
1218 netdev_info(ndev, "Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1219 fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
1220 fep->phy_dev->irq);
418bd0d4 1221
e6b043d5 1222 return 0;
1da177e4
LT
1223}
1224
e6b043d5 1225static int fec_enet_mii_init(struct platform_device *pdev)
562d2f8c 1226{
b5680e0b 1227 static struct mii_bus *fec0_mii_bus;
c556167f
UKK
1228 struct net_device *ndev = platform_get_drvdata(pdev);
1229 struct fec_enet_private *fep = netdev_priv(ndev);
b5680e0b
SG
1230 const struct platform_device_id *id_entry =
1231 platform_get_device_id(fep->pdev);
e6b043d5 1232 int err = -ENXIO, i;
6b265293 1233
b5680e0b
SG
1234 /*
1235 * The dual fec interfaces are not equivalent with enet-mac.
1236 * Here are the differences:
1237 *
1238 * - fec0 supports MII & RMII modes while fec1 only supports RMII
1239 * - fec0 acts as the 1588 time master while fec1 is slave
1240 * - external phys can only be configured by fec0
1241 *
1242 * That is to say fec1 can not work independently. It only works
1243 * when fec0 is working. The reason behind this design is that the
1244 * second interface is added primarily for Switch mode.
1245 *
1246 * Because of the last point above, both phys are attached on fec0
1247 * mdio interface in board design, and need to be configured by
1248 * fec0 mii_bus.
1249 */
43af940c 1250 if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && fep->dev_id > 0) {
b5680e0b 1251 /* fec1 uses fec0 mii_bus */
e163cc97
LW
1252 if (mii_cnt && fec0_mii_bus) {
1253 fep->mii_bus = fec0_mii_bus;
1254 mii_cnt++;
1255 return 0;
1256 }
1257 return -ENOENT;
b5680e0b
SG
1258 }
1259
e6b043d5 1260 fep->mii_timeout = 0;
1da177e4 1261
e6b043d5
BW
1262 /*
1263 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
230dec61
SG
1264 *
1265 * The formula for FEC MDC is 'ref_freq / (MII_SPEED x 2)' while
1266 * for ENET-MAC is 'ref_freq / ((MII_SPEED + 1) x 2)'. The i.MX28
1267 * Reference Manual has an error on this, and gets fixed on i.MX6Q
1268 * document.
e6b043d5 1269 */
f4d40de3 1270 fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ahb), 5000000);
230dec61
SG
1271 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1272 fep->phy_speed--;
1273 fep->phy_speed <<= 1;
e6b043d5 1274 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
1da177e4 1275
e6b043d5
BW
1276 fep->mii_bus = mdiobus_alloc();
1277 if (fep->mii_bus == NULL) {
1278 err = -ENOMEM;
1279 goto err_out;
1da177e4
LT
1280 }
1281
e6b043d5
BW
1282 fep->mii_bus->name = "fec_enet_mii_bus";
1283 fep->mii_bus->read = fec_enet_mdio_read;
1284 fep->mii_bus->write = fec_enet_mdio_write;
1285 fep->mii_bus->reset = fec_enet_mdio_reset;
391420f7
FF
1286 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1287 pdev->name, fep->dev_id + 1);
e6b043d5
BW
1288 fep->mii_bus->priv = fep;
1289 fep->mii_bus->parent = &pdev->dev;
1290
1291 fep->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
1292 if (!fep->mii_bus->irq) {
1293 err = -ENOMEM;
1294 goto err_out_free_mdiobus;
1da177e4
LT
1295 }
1296
e6b043d5
BW
1297 for (i = 0; i < PHY_MAX_ADDR; i++)
1298 fep->mii_bus->irq[i] = PHY_POLL;
1da177e4 1299
e6b043d5
BW
1300 if (mdiobus_register(fep->mii_bus))
1301 goto err_out_free_mdio_irq;
1da177e4 1302
e163cc97
LW
1303 mii_cnt++;
1304
b5680e0b
SG
1305 /* save fec0 mii_bus */
1306 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
1307 fec0_mii_bus = fep->mii_bus;
1308
e6b043d5 1309 return 0;
1da177e4 1310
e6b043d5
BW
1311err_out_free_mdio_irq:
1312 kfree(fep->mii_bus->irq);
1313err_out_free_mdiobus:
1314 mdiobus_free(fep->mii_bus);
1315err_out:
1316 return err;
1da177e4
LT
1317}
1318
e6b043d5 1319static void fec_enet_mii_remove(struct fec_enet_private *fep)
1da177e4 1320{
e163cc97
LW
1321 if (--mii_cnt == 0) {
1322 mdiobus_unregister(fep->mii_bus);
1323 kfree(fep->mii_bus->irq);
1324 mdiobus_free(fep->mii_bus);
1325 }
1da177e4
LT
1326}
1327
c556167f 1328static int fec_enet_get_settings(struct net_device *ndev,
e6b043d5 1329 struct ethtool_cmd *cmd)
1da177e4 1330{
c556167f 1331 struct fec_enet_private *fep = netdev_priv(ndev);
e6b043d5 1332 struct phy_device *phydev = fep->phy_dev;
1da177e4 1333
e6b043d5
BW
1334 if (!phydev)
1335 return -ENODEV;
1da177e4 1336
e6b043d5 1337 return phy_ethtool_gset(phydev, cmd);
1da177e4
LT
1338}
1339
c556167f 1340static int fec_enet_set_settings(struct net_device *ndev,
e6b043d5 1341 struct ethtool_cmd *cmd)
1da177e4 1342{
c556167f 1343 struct fec_enet_private *fep = netdev_priv(ndev);
e6b043d5 1344 struct phy_device *phydev = fep->phy_dev;
1da177e4 1345
e6b043d5
BW
1346 if (!phydev)
1347 return -ENODEV;
1da177e4 1348
e6b043d5 1349 return phy_ethtool_sset(phydev, cmd);
1da177e4
LT
1350}
1351
c556167f 1352static void fec_enet_get_drvinfo(struct net_device *ndev,
e6b043d5 1353 struct ethtool_drvinfo *info)
1da177e4 1354{
c556167f 1355 struct fec_enet_private *fep = netdev_priv(ndev);
6aa20a22 1356
7826d43f
JP
1357 strlcpy(info->driver, fep->pdev->dev.driver->name,
1358 sizeof(info->driver));
1359 strlcpy(info->version, "Revision: 1.0", sizeof(info->version));
1360 strlcpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info));
1da177e4
LT
1361}
1362
5ebae489
FL
1363static int fec_enet_get_ts_info(struct net_device *ndev,
1364 struct ethtool_ts_info *info)
1365{
1366 struct fec_enet_private *fep = netdev_priv(ndev);
1367
1368 if (fep->bufdesc_ex) {
1369
1370 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1371 SOF_TIMESTAMPING_RX_SOFTWARE |
1372 SOF_TIMESTAMPING_SOFTWARE |
1373 SOF_TIMESTAMPING_TX_HARDWARE |
1374 SOF_TIMESTAMPING_RX_HARDWARE |
1375 SOF_TIMESTAMPING_RAW_HARDWARE;
1376 if (fep->ptp_clock)
1377 info->phc_index = ptp_clock_index(fep->ptp_clock);
1378 else
1379 info->phc_index = -1;
1380
1381 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1382 (1 << HWTSTAMP_TX_ON);
1383
1384 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1385 (1 << HWTSTAMP_FILTER_ALL);
1386 return 0;
1387 } else {
1388 return ethtool_op_get_ts_info(ndev, info);
1389 }
1390}
1391
baa70a5c
FL
1392static void fec_enet_get_pauseparam(struct net_device *ndev,
1393 struct ethtool_pauseparam *pause)
1394{
1395 struct fec_enet_private *fep = netdev_priv(ndev);
1396
1397 pause->autoneg = (fep->pause_flag & FEC_PAUSE_FLAG_AUTONEG) != 0;
1398 pause->tx_pause = (fep->pause_flag & FEC_PAUSE_FLAG_ENABLE) != 0;
1399 pause->rx_pause = pause->tx_pause;
1400}
1401
1402static int fec_enet_set_pauseparam(struct net_device *ndev,
1403 struct ethtool_pauseparam *pause)
1404{
1405 struct fec_enet_private *fep = netdev_priv(ndev);
1406
1407 if (pause->tx_pause != pause->rx_pause) {
1408 netdev_info(ndev,
1409 "hardware only support enable/disable both tx and rx");
1410 return -EINVAL;
1411 }
1412
1413 fep->pause_flag = 0;
1414
1415 /* tx pause must be same as rx pause */
1416 fep->pause_flag |= pause->rx_pause ? FEC_PAUSE_FLAG_ENABLE : 0;
1417 fep->pause_flag |= pause->autoneg ? FEC_PAUSE_FLAG_AUTONEG : 0;
1418
1419 if (pause->rx_pause || pause->autoneg) {
1420 fep->phy_dev->supported |= ADVERTISED_Pause;
1421 fep->phy_dev->advertising |= ADVERTISED_Pause;
1422 } else {
1423 fep->phy_dev->supported &= ~ADVERTISED_Pause;
1424 fep->phy_dev->advertising &= ~ADVERTISED_Pause;
1425 }
1426
1427 if (pause->autoneg) {
1428 if (netif_running(ndev))
1429 fec_stop(ndev);
1430 phy_start_aneg(fep->phy_dev);
1431 }
1432 if (netif_running(ndev))
1433 fec_restart(ndev, 0);
1434
1435 return 0;
1436}
1437
9b07be4b 1438static const struct ethtool_ops fec_enet_ethtool_ops = {
baa70a5c
FL
1439 .get_pauseparam = fec_enet_get_pauseparam,
1440 .set_pauseparam = fec_enet_set_pauseparam,
e6b043d5
BW
1441 .get_settings = fec_enet_get_settings,
1442 .set_settings = fec_enet_set_settings,
1443 .get_drvinfo = fec_enet_get_drvinfo,
1444 .get_link = ethtool_op_get_link,
5ebae489 1445 .get_ts_info = fec_enet_get_ts_info,
e6b043d5 1446};
1da177e4 1447
c556167f 1448static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
1da177e4 1449{
c556167f 1450 struct fec_enet_private *fep = netdev_priv(ndev);
e6b043d5 1451 struct phy_device *phydev = fep->phy_dev;
1da177e4 1452
c556167f 1453 if (!netif_running(ndev))
e6b043d5 1454 return -EINVAL;
1da177e4 1455
e6b043d5
BW
1456 if (!phydev)
1457 return -ENODEV;
1458
ff43da86 1459 if (cmd == SIOCSHWTSTAMP && fep->bufdesc_ex)
6605b730 1460 return fec_ptp_ioctl(ndev, rq, cmd);
ff43da86 1461
28b04113 1462 return phy_mii_ioctl(phydev, rq, cmd);
1da177e4
LT
1463}
1464
c556167f 1465static void fec_enet_free_buffers(struct net_device *ndev)
f0b3fbea 1466{
c556167f 1467 struct fec_enet_private *fep = netdev_priv(ndev);
da2191e3 1468 unsigned int i;
f0b3fbea
SH
1469 struct sk_buff *skb;
1470 struct bufdesc *bdp;
1471
1472 bdp = fep->rx_bd_base;
1473 for (i = 0; i < RX_RING_SIZE; i++) {
1474 skb = fep->rx_skbuff[i];
1475
1476 if (bdp->cbd_bufaddr)
d1ab1f54 1477 dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
f0b3fbea
SH
1478 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
1479 if (skb)
1480 dev_kfree_skb(skb);
ff43da86 1481 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
f0b3fbea
SH
1482 }
1483
1484 bdp = fep->tx_bd_base;
1485 for (i = 0; i < TX_RING_SIZE; i++)
1486 kfree(fep->tx_bounce[i]);
1487}
1488
c556167f 1489static int fec_enet_alloc_buffers(struct net_device *ndev)
f0b3fbea 1490{
c556167f 1491 struct fec_enet_private *fep = netdev_priv(ndev);
da2191e3 1492 unsigned int i;
f0b3fbea
SH
1493 struct sk_buff *skb;
1494 struct bufdesc *bdp;
1495
1496 bdp = fep->rx_bd_base;
1497 for (i = 0; i < RX_RING_SIZE; i++) {
b72061a3 1498 skb = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
f0b3fbea 1499 if (!skb) {
c556167f 1500 fec_enet_free_buffers(ndev);
f0b3fbea
SH
1501 return -ENOMEM;
1502 }
1503 fep->rx_skbuff[i] = skb;
1504
d1ab1f54 1505 bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
f0b3fbea
SH
1506 FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
1507 bdp->cbd_sc = BD_ENET_RX_EMPTY;
ff43da86
FL
1508
1509 if (fep->bufdesc_ex) {
1510 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
1511 ebdp->cbd_esc = BD_ENET_RX_INT;
1512 }
1513
1514 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
f0b3fbea
SH
1515 }
1516
1517 /* Set the last buffer to wrap. */
ff43da86 1518 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
f0b3fbea
SH
1519 bdp->cbd_sc |= BD_SC_WRAP;
1520
1521 bdp = fep->tx_bd_base;
1522 for (i = 0; i < TX_RING_SIZE; i++) {
1523 fep->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL);
1524
1525 bdp->cbd_sc = 0;
1526 bdp->cbd_bufaddr = 0;
6605b730 1527
ff43da86
FL
1528 if (fep->bufdesc_ex) {
1529 struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
96d2222b 1530 ebdp->cbd_esc = BD_ENET_TX_INT;
ff43da86
FL
1531 }
1532
1533 bdp = fec_enet_get_nextdesc(bdp, fep->bufdesc_ex);
f0b3fbea
SH
1534 }
1535
1536 /* Set the last buffer to wrap. */
ff43da86 1537 bdp = fec_enet_get_prevdesc(bdp, fep->bufdesc_ex);
f0b3fbea
SH
1538 bdp->cbd_sc |= BD_SC_WRAP;
1539
1540 return 0;
1541}
1542
1da177e4 1543static int
c556167f 1544fec_enet_open(struct net_device *ndev)
1da177e4 1545{
c556167f 1546 struct fec_enet_private *fep = netdev_priv(ndev);
f0b3fbea 1547 int ret;
1da177e4 1548
dc975382
FL
1549 napi_enable(&fep->napi);
1550
1da177e4
LT
1551 /* I should reset the ring buffers here, but I don't yet know
1552 * a simple way to do that.
1553 */
1da177e4 1554
c556167f 1555 ret = fec_enet_alloc_buffers(ndev);
f0b3fbea
SH
1556 if (ret)
1557 return ret;
1558
418bd0d4 1559 /* Probe and connect to PHY when open the interface */
c556167f 1560 ret = fec_enet_mii_probe(ndev);
418bd0d4 1561 if (ret) {
c556167f 1562 fec_enet_free_buffers(ndev);
418bd0d4
BW
1563 return ret;
1564 }
e6b043d5 1565 phy_start(fep->phy_dev);
c556167f 1566 netif_start_queue(ndev);
1da177e4 1567 fep->opened = 1;
22f6b860 1568 return 0;
1da177e4
LT
1569}
1570
1571static int
c556167f 1572fec_enet_close(struct net_device *ndev)
1da177e4 1573{
c556167f 1574 struct fec_enet_private *fep = netdev_priv(ndev);
1da177e4 1575
22f6b860 1576 /* Don't know what to do yet. */
3f104c38 1577 napi_disable(&fep->napi);
1da177e4 1578 fep->opened = 0;
c556167f
UKK
1579 netif_stop_queue(ndev);
1580 fec_stop(ndev);
1da177e4 1581
e497ba82
UKK
1582 if (fep->phy_dev) {
1583 phy_stop(fep->phy_dev);
418bd0d4 1584 phy_disconnect(fep->phy_dev);
e497ba82 1585 }
418bd0d4 1586
db8880bc 1587 fec_enet_free_buffers(ndev);
f0b3fbea 1588
1da177e4
LT
1589 return 0;
1590}
1591
1da177e4
LT
1592/* Set or clear the multicast filter for this adaptor.
1593 * Skeleton taken from sunlance driver.
1594 * The CPM Ethernet implementation allows Multicast as well as individual
1595 * MAC address filtering. Some of the drivers check to make sure it is
1596 * a group multicast address, and discard those that are not. I guess I
1597 * will do the same for now, but just remove the test if you want
1598 * individual filtering as well (do the upper net layers want or support
1599 * this kind of feature?).
1600 */
1601
1602#define HASH_BITS 6 /* #bits in hash */
1603#define CRC32_POLY 0xEDB88320
1604
c556167f 1605static void set_multicast_list(struct net_device *ndev)
1da177e4 1606{
c556167f 1607 struct fec_enet_private *fep = netdev_priv(ndev);
22bedad3 1608 struct netdev_hw_addr *ha;
48e2f183 1609 unsigned int i, bit, data, crc, tmp;
1da177e4
LT
1610 unsigned char hash;
1611
c556167f 1612 if (ndev->flags & IFF_PROMISC) {
f44d6305
SH
1613 tmp = readl(fep->hwp + FEC_R_CNTRL);
1614 tmp |= 0x8;
1615 writel(tmp, fep->hwp + FEC_R_CNTRL);
4e831836
SH
1616 return;
1617 }
1da177e4 1618
4e831836
SH
1619 tmp = readl(fep->hwp + FEC_R_CNTRL);
1620 tmp &= ~0x8;
1621 writel(tmp, fep->hwp + FEC_R_CNTRL);
1622
c556167f 1623 if (ndev->flags & IFF_ALLMULTI) {
4e831836
SH
1624 /* Catch all multicast addresses, so set the
1625 * filter to all 1's
1626 */
1627 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1628 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1629
1630 return;
1631 }
1632
1633 /* Clear filter and add the addresses in hash register
1634 */
1635 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1636 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1637
c556167f 1638 netdev_for_each_mc_addr(ha, ndev) {
4e831836
SH
1639 /* calculate crc32 value of mac address */
1640 crc = 0xffffffff;
1641
c556167f 1642 for (i = 0; i < ndev->addr_len; i++) {
22bedad3 1643 data = ha->addr[i];
4e831836
SH
1644 for (bit = 0; bit < 8; bit++, data >>= 1) {
1645 crc = (crc >> 1) ^
1646 (((crc ^ data) & 1) ? CRC32_POLY : 0);
1da177e4
LT
1647 }
1648 }
4e831836
SH
1649
1650 /* only upper 6 bits (HASH_BITS) are used
1651 * which point to specific bit in he hash registers
1652 */
1653 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
1654
1655 if (hash > 31) {
1656 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1657 tmp |= 1 << (hash - 32);
1658 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1659 } else {
1660 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1661 tmp |= 1 << hash;
1662 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1663 }
1da177e4
LT
1664 }
1665}
1666
22f6b860 1667/* Set a MAC change in hardware. */
009fda83 1668static int
c556167f 1669fec_set_mac_address(struct net_device *ndev, void *p)
1da177e4 1670{
c556167f 1671 struct fec_enet_private *fep = netdev_priv(ndev);
009fda83
SH
1672 struct sockaddr *addr = p;
1673
1674 if (!is_valid_ether_addr(addr->sa_data))
1675 return -EADDRNOTAVAIL;
1676
c556167f 1677 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
1da177e4 1678
c556167f
UKK
1679 writel(ndev->dev_addr[3] | (ndev->dev_addr[2] << 8) |
1680 (ndev->dev_addr[1] << 16) | (ndev->dev_addr[0] << 24),
f44d6305 1681 fep->hwp + FEC_ADDR_LOW);
c556167f 1682 writel((ndev->dev_addr[5] << 16) | (ndev->dev_addr[4] << 24),
7cff0943 1683 fep->hwp + FEC_ADDR_HIGH);
009fda83 1684 return 0;
1da177e4
LT
1685}
1686
7f5c6add 1687#ifdef CONFIG_NET_POLL_CONTROLLER
49ce9c2c
BH
1688/**
1689 * fec_poll_controller - FEC Poll controller function
7f5c6add
XJ
1690 * @dev: The FEC network adapter
1691 *
1692 * Polled functionality used by netconsole and others in non interrupt mode
1693 *
1694 */
47a5247f 1695static void fec_poll_controller(struct net_device *dev)
7f5c6add
XJ
1696{
1697 int i;
1698 struct fec_enet_private *fep = netdev_priv(dev);
1699
1700 for (i = 0; i < FEC_IRQ_NUM; i++) {
1701 if (fep->irq[i] > 0) {
1702 disable_irq(fep->irq[i]);
1703 fec_enet_interrupt(fep->irq[i], dev);
1704 enable_irq(fep->irq[i]);
1705 }
1706 }
1707}
1708#endif
1709
4c09eed9
JB
1710static int fec_set_features(struct net_device *netdev,
1711 netdev_features_t features)
1712{
1713 struct fec_enet_private *fep = netdev_priv(netdev);
1714 netdev_features_t changed = features ^ netdev->features;
1715
1716 netdev->features = features;
1717
1718 /* Receive checksum has been changed */
1719 if (changed & NETIF_F_RXCSUM) {
1720 if (features & NETIF_F_RXCSUM)
1721 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
1722 else
1723 fep->csum_flags &= ~FLAG_RX_CSUM_ENABLED;
1724
1725 if (netif_running(netdev)) {
1726 fec_stop(netdev);
1727 fec_restart(netdev, fep->phy_dev->duplex);
1728 netif_wake_queue(netdev);
1729 } else {
1730 fec_restart(netdev, fep->phy_dev->duplex);
1731 }
1732 }
1733
1734 return 0;
1735}
1736
009fda83
SH
1737static const struct net_device_ops fec_netdev_ops = {
1738 .ndo_open = fec_enet_open,
1739 .ndo_stop = fec_enet_close,
1740 .ndo_start_xmit = fec_enet_start_xmit,
afc4b13d 1741 .ndo_set_rx_mode = set_multicast_list,
635ecaa7 1742 .ndo_change_mtu = eth_change_mtu,
009fda83
SH
1743 .ndo_validate_addr = eth_validate_addr,
1744 .ndo_tx_timeout = fec_timeout,
1745 .ndo_set_mac_address = fec_set_mac_address,
db8880bc 1746 .ndo_do_ioctl = fec_enet_ioctl,
7f5c6add
XJ
1747#ifdef CONFIG_NET_POLL_CONTROLLER
1748 .ndo_poll_controller = fec_poll_controller,
1749#endif
4c09eed9 1750 .ndo_set_features = fec_set_features,
009fda83
SH
1751};
1752
1da177e4
LT
1753 /*
1754 * XXX: We need to clean up on failure exits here.
ead73183 1755 *
1da177e4 1756 */
c556167f 1757static int fec_enet_init(struct net_device *ndev)
1da177e4 1758{
c556167f 1759 struct fec_enet_private *fep = netdev_priv(ndev);
48496255
SG
1760 const struct platform_device_id *id_entry =
1761 platform_get_device_id(fep->pdev);
f0b3fbea 1762 struct bufdesc *cbd_base;
1da177e4 1763
8d4dd5cf
SH
1764 /* Allocate memory for buffer descriptors. */
1765 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
d0320f75
JP
1766 GFP_KERNEL);
1767 if (!cbd_base)
562d2f8c 1768 return -ENOMEM;
562d2f8c 1769
14109a59 1770 memset(cbd_base, 0, PAGE_SIZE);
3b2b74ca 1771
c556167f 1772 fep->netdev = ndev;
1da177e4 1773
49da97dc 1774 /* Get the Ethernet address */
c556167f 1775 fec_get_mac(ndev);
1da177e4 1776
8d4dd5cf 1777 /* Set receive and transmit descriptor base. */
1da177e4 1778 fep->rx_bd_base = cbd_base;
ff43da86
FL
1779 if (fep->bufdesc_ex)
1780 fep->tx_bd_base = (struct bufdesc *)
1781 (((struct bufdesc_ex *)cbd_base) + RX_RING_SIZE);
1782 else
1783 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
1da177e4 1784
22f6b860 1785 /* The FEC Ethernet specific entries in the device structure */
c556167f
UKK
1786 ndev->watchdog_timeo = TX_TIMEOUT;
1787 ndev->netdev_ops = &fec_netdev_ops;
1788 ndev->ethtool_ops = &fec_enet_ethtool_ops;
633e7533 1789
dc975382
FL
1790 writel(FEC_RX_DISABLED_IMASK, fep->hwp + FEC_IMASK);
1791 netif_napi_add(ndev, &fep->napi, fec_enet_rx_napi, FEC_NAPI_WEIGHT);
1792
48496255
SG
1793 if (id_entry->driver_data & FEC_QUIRK_HAS_CSUM) {
1794 /* enable hw accelerator */
1795 ndev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
1796 | NETIF_F_RXCSUM);
1797 ndev->hw_features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
1798 | NETIF_F_RXCSUM);
1799 fep->csum_flags |= FLAG_RX_CSUM_ENABLED;
1800 }
4c09eed9 1801
c556167f 1802 fec_restart(ndev, 0);
1da177e4 1803
1da177e4
LT
1804 return 0;
1805}
1806
ca2cc333 1807#ifdef CONFIG_OF
33897cc8 1808static void fec_reset_phy(struct platform_device *pdev)
ca2cc333
SG
1809{
1810 int err, phy_reset;
a3caad0a 1811 int msec = 1;
ca2cc333
SG
1812 struct device_node *np = pdev->dev.of_node;
1813
1814 if (!np)
a9b2c8ef 1815 return;
ca2cc333 1816
a3caad0a
SG
1817 of_property_read_u32(np, "phy-reset-duration", &msec);
1818 /* A sane reset duration should not be longer than 1s */
1819 if (msec > 1000)
1820 msec = 1;
1821
ca2cc333 1822 phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
07dcf8e9
FE
1823 if (!gpio_is_valid(phy_reset))
1824 return;
1825
119fc007
SG
1826 err = devm_gpio_request_one(&pdev->dev, phy_reset,
1827 GPIOF_OUT_INIT_LOW, "phy-reset");
ca2cc333 1828 if (err) {
07dcf8e9 1829 dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
a9b2c8ef 1830 return;
ca2cc333 1831 }
a3caad0a 1832 msleep(msec);
ca2cc333 1833 gpio_set_value(phy_reset, 1);
ca2cc333
SG
1834}
1835#else /* CONFIG_OF */
0c7768a0 1836static void fec_reset_phy(struct platform_device *pdev)
ca2cc333
SG
1837{
1838 /*
1839 * In case of platform probe, the reset has been done
1840 * by machine code.
1841 */
ca2cc333
SG
1842}
1843#endif /* CONFIG_OF */
1844
33897cc8 1845static int
ead73183
SH
1846fec_probe(struct platform_device *pdev)
1847{
1848 struct fec_enet_private *fep;
5eb32bd0 1849 struct fec_platform_data *pdata;
ead73183
SH
1850 struct net_device *ndev;
1851 int i, irq, ret = 0;
1852 struct resource *r;
ca2cc333 1853 const struct of_device_id *of_id;
43af940c 1854 static int dev_id;
ca2cc333
SG
1855
1856 of_id = of_match_device(fec_dt_ids, &pdev->dev);
1857 if (of_id)
1858 pdev->id_entry = of_id->data;
ead73183
SH
1859
1860 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1861 if (!r)
1862 return -ENXIO;
1863
ead73183
SH
1864 /* Init network device */
1865 ndev = alloc_etherdev(sizeof(struct fec_enet_private));
83e519b6
FE
1866 if (!ndev)
1867 return -ENOMEM;
ead73183
SH
1868
1869 SET_NETDEV_DEV(ndev, &pdev->dev);
1870
1871 /* setup board info structure */
1872 fep = netdev_priv(ndev);
ead73183 1873
baa70a5c
FL
1874 /* default enable pause frame auto negotiation */
1875 if (pdev->id_entry &&
1876 (pdev->id_entry->driver_data & FEC_QUIRK_HAS_GBIT))
1877 fep->pause_flag |= FEC_PAUSE_FLAG_AUTONEG;
1878
83e519b6 1879 fep->hwp = devm_request_and_ioremap(&pdev->dev, r);
e6b043d5 1880 fep->pdev = pdev;
43af940c 1881 fep->dev_id = dev_id++;
ead73183 1882
ff43da86
FL
1883 fep->bufdesc_ex = 0;
1884
24e531b4 1885 if (!fep->hwp) {
ead73183
SH
1886 ret = -ENOMEM;
1887 goto failed_ioremap;
1888 }
1889
1890 platform_set_drvdata(pdev, ndev);
1891
6c5f7808 1892 ret = of_get_phy_mode(pdev->dev.of_node);
ca2cc333
SG
1893 if (ret < 0) {
1894 pdata = pdev->dev.platform_data;
1895 if (pdata)
1896 fep->phy_interface = pdata->phy;
1897 else
1898 fep->phy_interface = PHY_INTERFACE_MODE_MII;
1899 } else {
1900 fep->phy_interface = ret;
1901 }
1902
f4d40de3
SH
1903 fep->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
1904 if (IS_ERR(fep->clk_ipg)) {
1905 ret = PTR_ERR(fep->clk_ipg);
ead73183
SH
1906 goto failed_clk;
1907 }
f4d40de3
SH
1908
1909 fep->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
1910 if (IS_ERR(fep->clk_ahb)) {
1911 ret = PTR_ERR(fep->clk_ahb);
1912 goto failed_clk;
1913 }
1914
daa7d392
WS
1915 /* enet_out is optional, depends on board */
1916 fep->clk_enet_out = devm_clk_get(&pdev->dev, "enet_out");
1917 if (IS_ERR(fep->clk_enet_out))
1918 fep->clk_enet_out = NULL;
1919
6605b730 1920 fep->clk_ptp = devm_clk_get(&pdev->dev, "ptp");
e2f8d555
FE
1921 fep->bufdesc_ex =
1922 pdev->id_entry->driver_data & FEC_QUIRK_HAS_BUFDESC_EX;
6605b730 1923 if (IS_ERR(fep->clk_ptp)) {
c29dc2d7 1924 fep->clk_ptp = NULL;
ff43da86 1925 fep->bufdesc_ex = 0;
6605b730 1926 }
6605b730 1927
f4d40de3
SH
1928 clk_prepare_enable(fep->clk_ahb);
1929 clk_prepare_enable(fep->clk_ipg);
daa7d392 1930 clk_prepare_enable(fep->clk_enet_out);
c29dc2d7 1931 clk_prepare_enable(fep->clk_ptp);
ff43da86 1932
f4e9f3d2
FE
1933 fep->reg_phy = devm_regulator_get(&pdev->dev, "phy");
1934 if (!IS_ERR(fep->reg_phy)) {
1935 ret = regulator_enable(fep->reg_phy);
5fa9c0fe
SG
1936 if (ret) {
1937 dev_err(&pdev->dev,
1938 "Failed to enable phy regulator: %d\n", ret);
1939 goto failed_regulator;
1940 }
f6a4d607
FE
1941 } else {
1942 fep->reg_phy = NULL;
5fa9c0fe
SG
1943 }
1944
2ca9b2aa
SG
1945 fec_reset_phy(pdev);
1946
e2f8d555 1947 if (fep->bufdesc_ex)
ca162a82 1948 fec_ptp_init(pdev);
e2f8d555
FE
1949
1950 ret = fec_enet_init(ndev);
1951 if (ret)
1952 goto failed_init;
1953
1954 for (i = 0; i < FEC_IRQ_NUM; i++) {
1955 irq = platform_get_irq(pdev, i);
1956 if (irq < 0) {
1957 if (i)
1958 break;
1959 ret = irq;
1960 goto failed_irq;
1961 }
1962 ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
1963 if (ret) {
1964 while (--i >= 0) {
1965 irq = platform_get_irq(pdev, i);
1966 free_irq(irq, ndev);
1967 }
1968 goto failed_irq;
1969 }
1970 }
1971
e6b043d5
BW
1972 ret = fec_enet_mii_init(pdev);
1973 if (ret)
1974 goto failed_mii_init;
1975
03c698c9
OS
1976 /* Carrier starts down, phylib will bring it up */
1977 netif_carrier_off(ndev);
1978
ead73183
SH
1979 ret = register_netdev(ndev);
1980 if (ret)
1981 goto failed_register;
1982
eb1d0640
FE
1983 if (fep->bufdesc_ex && fep->ptp_clock)
1984 netdev_info(ndev, "registered PHC device %d\n", fep->dev_id);
1985
54309fa6 1986 INIT_DELAYED_WORK(&(fep->delay_work.delay_work), fec_enet_work);
ead73183
SH
1987 return 0;
1988
1989failed_register:
e6b043d5
BW
1990 fec_enet_mii_remove(fep);
1991failed_mii_init:
7a2bbd8d 1992failed_irq:
e2f8d555
FE
1993 for (i = 0; i < FEC_IRQ_NUM; i++) {
1994 irq = platform_get_irq(pdev, i);
1995 if (irq > 0)
1996 free_irq(irq, ndev);
1997 }
7a2bbd8d 1998failed_init:
f6a4d607
FE
1999 if (fep->reg_phy)
2000 regulator_disable(fep->reg_phy);
5fa9c0fe 2001failed_regulator:
f4d40de3
SH
2002 clk_disable_unprepare(fep->clk_ahb);
2003 clk_disable_unprepare(fep->clk_ipg);
daa7d392 2004 clk_disable_unprepare(fep->clk_enet_out);
c29dc2d7 2005 clk_disable_unprepare(fep->clk_ptp);
ead73183 2006failed_clk:
ead73183
SH
2007failed_ioremap:
2008 free_netdev(ndev);
2009
2010 return ret;
2011}
2012
33897cc8 2013static int
ead73183
SH
2014fec_drv_remove(struct platform_device *pdev)
2015{
2016 struct net_device *ndev = platform_get_drvdata(pdev);
2017 struct fec_enet_private *fep = netdev_priv(ndev);
e163cc97 2018 int i;
ead73183 2019
54309fa6 2020 cancel_delayed_work_sync(&(fep->delay_work.delay_work));
e163cc97 2021 unregister_netdev(ndev);
e6b043d5 2022 fec_enet_mii_remove(fep);
6605b730 2023 del_timer_sync(&fep->time_keep);
c55284e4
FE
2024 for (i = 0; i < FEC_IRQ_NUM; i++) {
2025 int irq = platform_get_irq(pdev, i);
2026 if (irq > 0)
2027 free_irq(irq, ndev);
2028 }
f6a4d607
FE
2029 if (fep->reg_phy)
2030 regulator_disable(fep->reg_phy);
6605b730
FL
2031 clk_disable_unprepare(fep->clk_ptp);
2032 if (fep->ptp_clock)
2033 ptp_clock_unregister(fep->ptp_clock);
daa7d392 2034 clk_disable_unprepare(fep->clk_enet_out);
f4d40de3
SH
2035 clk_disable_unprepare(fep->clk_ahb);
2036 clk_disable_unprepare(fep->clk_ipg);
ead73183 2037 free_netdev(ndev);
28e2188e 2038
ead73183
SH
2039 return 0;
2040}
2041
bf7bfd7f 2042#ifdef CONFIG_PM_SLEEP
ead73183 2043static int
87cad5c3 2044fec_suspend(struct device *dev)
ead73183 2045{
87cad5c3 2046 struct net_device *ndev = dev_get_drvdata(dev);
04e5216d 2047 struct fec_enet_private *fep = netdev_priv(ndev);
ead73183 2048
04e5216d
UKK
2049 if (netif_running(ndev)) {
2050 fec_stop(ndev);
2051 netif_device_detach(ndev);
ead73183 2052 }
daa7d392 2053 clk_disable_unprepare(fep->clk_enet_out);
f4d40de3
SH
2054 clk_disable_unprepare(fep->clk_ahb);
2055 clk_disable_unprepare(fep->clk_ipg);
04e5216d 2056
238f7bc7
FE
2057 if (fep->reg_phy)
2058 regulator_disable(fep->reg_phy);
2059
ead73183
SH
2060 return 0;
2061}
2062
2063static int
87cad5c3 2064fec_resume(struct device *dev)
ead73183 2065{
87cad5c3 2066 struct net_device *ndev = dev_get_drvdata(dev);
04e5216d 2067 struct fec_enet_private *fep = netdev_priv(ndev);
238f7bc7
FE
2068 int ret;
2069
2070 if (fep->reg_phy) {
2071 ret = regulator_enable(fep->reg_phy);
2072 if (ret)
2073 return ret;
2074 }
ead73183 2075
daa7d392 2076 clk_prepare_enable(fep->clk_enet_out);
f4d40de3
SH
2077 clk_prepare_enable(fep->clk_ahb);
2078 clk_prepare_enable(fep->clk_ipg);
04e5216d
UKK
2079 if (netif_running(ndev)) {
2080 fec_restart(ndev, fep->full_duplex);
2081 netif_device_attach(ndev);
ead73183 2082 }
04e5216d 2083
ead73183
SH
2084 return 0;
2085}
bf7bfd7f 2086#endif /* CONFIG_PM_SLEEP */
ead73183 2087
bf7bfd7f 2088static SIMPLE_DEV_PM_OPS(fec_pm_ops, fec_suspend, fec_resume);
59d4289b 2089
ead73183
SH
2090static struct platform_driver fec_driver = {
2091 .driver = {
b5680e0b 2092 .name = DRIVER_NAME,
87cad5c3 2093 .owner = THIS_MODULE,
87cad5c3 2094 .pm = &fec_pm_ops,
ca2cc333 2095 .of_match_table = fec_dt_ids,
ead73183 2096 },
b5680e0b 2097 .id_table = fec_devtype,
87cad5c3 2098 .probe = fec_probe,
33897cc8 2099 .remove = fec_drv_remove,
ead73183
SH
2100};
2101
aaca2377 2102module_platform_driver(fec_driver);
1da177e4
LT
2103
2104MODULE_LICENSE("GPL");