blob: 54ee493768f1421e77b072b7f2f6a8a58a1b9e17 [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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/string.h>
25#include <linux/ptrace.h>
26#include <linux/errno.h>
27#include <linux/ioport.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/skbuff.h>
36#include <linux/spinlock.h>
37#include <linux/workqueue.h>
38#include <linux/bitops.h>
Sascha Hauer6f501b12009-01-28 23:03:05 +000039#include <linux/io.h>
40#include <linux/irq.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000041#include <linux/clk.h>
Sascha Haueread73182009-01-28 23:03:11 +000042#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Greg Ungerer080853a2007-07-30 16:28:46 +100044#include <asm/cacheflush.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000045
46#ifndef CONFIG_ARCH_MXC
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/coldfire.h>
48#include <asm/mcfsim.h>
Sascha Hauer196719e2009-01-28 23:03:10 +000049#endif
Sascha Hauer6f501b12009-01-28 23:03:05 +000050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "fec.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Sascha Hauer196719e2009-01-28 23:03:10 +000053#ifdef CONFIG_ARCH_MXC
54#include <mach/hardware.h>
55#define FEC_ALIGNMENT 0xf
56#else
57#define FEC_ALIGNMENT 0x3
58#endif
59
Sascha Haueread73182009-01-28 23:03:11 +000060/*
61 * Define the fixed address of the FEC hardware.
62 */
Greg Ungerer87f4abb2008-06-06 15:55:36 +100063#if defined(CONFIG_M5272)
Sebastian Siewiorc1d96152008-05-01 14:04:02 +100064#define HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66static unsigned char fec_mac_default[] = {
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68};
69
70/*
71 * Some hardware gets it MAC address out of local flash memory.
72 * if this is non-zero then assume it is the address to get MAC from.
73 */
74#if defined(CONFIG_NETtel)
75#define FEC_FLASHMAC 0xf0006006
76#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
77#define FEC_FLASHMAC 0xf0006000
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#elif defined(CONFIG_CANCam)
79#define FEC_FLASHMAC 0xf0020000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100080#elif defined (CONFIG_M5272C3)
81#define FEC_FLASHMAC (0xffe04000 + 4)
82#elif defined(CONFIG_MOD5272)
83#define FEC_FLASHMAC 0xffc0406b
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#else
85#define FEC_FLASHMAC 0
86#endif
Greg Ungerer43be6362009-02-26 22:42:51 -080087#endif /* CONFIG_M5272 */
Sascha Haueread73182009-01-28 23:03:11 +000088
Sascha Hauer22f6b862009-04-15 01:32:18 +000089/* Forward declarations of some structures to support different PHYs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91typedef struct {
92 uint mii_data;
93 void (*funct)(uint mii_reg, struct net_device *dev);
94} phy_cmd_t;
95
96typedef struct {
97 uint id;
98 char *name;
99
100 const phy_cmd_t *config;
101 const phy_cmd_t *startup;
102 const phy_cmd_t *ack_int;
103 const phy_cmd_t *shutdown;
104} phy_info_t;
105
106/* The number of Tx and Rx buffers. These are allocated from the page
107 * pool. The code may assume these are power of two, so it it best
108 * to keep them that size.
109 * We don't need to allocate pages for the transmitter. We just use
110 * the skbuffer directly.
111 */
112#define FEC_ENET_RX_PAGES 8
113#define FEC_ENET_RX_FRSIZE 2048
114#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
115#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
116#define FEC_ENET_TX_FRSIZE 2048
117#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
118#define TX_RING_SIZE 16 /* Must be power of two */
119#define TX_RING_MOD_MASK 15 /* for this to work */
120
Greg Ungerer562d2f82005-11-07 14:09:50 +1000121#if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
Matt Waddel6b265292006-06-27 13:10:56 +1000122#error "FEC: descriptor ring size constants too large"
Greg Ungerer562d2f82005-11-07 14:09:50 +1000123#endif
124
Sascha Hauer22f6b862009-04-15 01:32:18 +0000125/* Interrupt events/masks. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
127#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
128#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
129#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
130#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
131#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
132#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
133#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
134#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
135#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
136
137/* The FEC stores dest/src/type, data, and checksum for receive packets.
138 */
139#define PKT_MAXBUF_SIZE 1518
140#define PKT_MINBUF_SIZE 64
141#define PKT_MAXBLR_SIZE 1520
142
143
144/*
Matt Waddel6b265292006-06-27 13:10:56 +1000145 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * size bits. Other FEC hardware does not, so we need to take that into
147 * account when setting it.
148 */
Greg Ungerer562d2f82005-11-07 14:09:50 +1000149#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
Sascha Hauer196719e2009-01-28 23:03:10 +0000150 defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARCH_MXC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
152#else
153#define OPT_FRAME_SIZE 0
154#endif
155
156/* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
157 * tx_bd_base always point to the base of the buffer descriptors. The
158 * cur_rx and cur_tx point to the currently available buffer.
159 * The dirty_tx tracks the current buffer that is being sent by the
160 * controller. The cur_tx and dirty_tx are equal under both completely
161 * empty and completely full conditions. The empty/ready indicator in
162 * the buffer descriptor determines the actual condition.
163 */
164struct fec_enet_private {
165 /* Hardware registers of the FEC device */
Sascha Hauerf44d6302009-04-15 03:11:30 +0000166 void __iomem *hwp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Greg Ungerercb84d6e2007-07-30 16:29:09 +1000168 struct net_device *netdev;
169
Sascha Haueread73182009-01-28 23:03:11 +0000170 struct clk *clk;
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
173 unsigned char *tx_bounce[TX_RING_SIZE];
174 struct sk_buff* tx_skbuff[TX_RING_SIZE];
175 ushort skb_cur;
176 ushort skb_dirty;
177
Sascha Hauer22f6b862009-04-15 01:32:18 +0000178 /* CPM dual port RAM relative addresses */
Sascha Hauer4661e752009-01-28 23:03:07 +0000179 dma_addr_t bd_dma;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000180 /* Address of Rx and Tx buffers */
Sascha Hauer2e285322009-04-15 01:32:16 +0000181 struct bufdesc *rx_bd_base;
182 struct bufdesc *tx_bd_base;
183 /* The next free ring entry */
184 struct bufdesc *cur_rx, *cur_tx;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000185 /* The ring entries to be free()ed */
Sascha Hauer2e285322009-04-15 01:32:16 +0000186 struct bufdesc *dirty_tx;
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 uint tx_full;
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000189 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
190 spinlock_t hw_lock;
191 /* hold while accessing the mii_list_t() elements */
192 spinlock_t mii_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 uint phy_id;
195 uint phy_id_done;
196 uint phy_status;
197 uint phy_speed;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000198 phy_info_t const *phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 struct work_struct phy_task;
200
201 uint sequence_done;
202 uint mii_phy_task_queued;
203
204 uint phy_addr;
205
206 int index;
207 int opened;
208 int link;
209 int old_link;
210 int full_duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211};
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213static void fec_enet_mii(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100214static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static void fec_enet_tx(struct net_device *dev);
216static void fec_enet_rx(struct net_device *dev);
217static int fec_enet_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static void fec_restart(struct net_device *dev, int duplex);
219static void fec_stop(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221
222/* MII processing. We keep this as simple as possible. Requests are
223 * placed on the list (if there is room). When the request is finished
224 * by the MII, an optional function may be called.
225 */
226typedef struct mii_list {
227 uint mii_regval;
228 void (*mii_func)(uint val, struct net_device *dev);
229 struct mii_list *mii_next;
230} mii_list_t;
231
232#define NMII 20
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000233static mii_list_t mii_cmds[NMII];
234static mii_list_t *mii_free;
235static mii_list_t *mii_head;
236static mii_list_t *mii_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400238static int mii_queue(struct net_device *dev, int request,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 void (*func)(uint, struct net_device *));
240
Sascha Hauer22f6b862009-04-15 01:32:18 +0000241/* Make MII read/write commands for the FEC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
243#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
244 (VAL & 0xffff))
245#define mk_mii_end 0
246
Sascha Hauer22f6b862009-04-15 01:32:18 +0000247/* Transmitter timeout */
248#define TX_TIMEOUT (2 * HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Sascha Hauer22f6b862009-04-15 01:32:18 +0000250/* Register definitions for the PHY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252#define MII_REG_CR 0 /* Control Register */
253#define MII_REG_SR 1 /* Status Register */
254#define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
255#define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400256#define MII_REG_ANAR 4 /* A-N Advertisement Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
258#define MII_REG_ANER 6 /* A-N Expansion Register */
259#define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
260#define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
261
262/* values for phy_status */
263
264#define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
265#define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
266#define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
267#define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400268#define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400270#define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272#define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
273#define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
274#define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
275#define PHY_STAT_SPMASK 0xf000 /* mask for speed */
276#define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400277#define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400279#define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281
282static int
283fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
284{
Sascha Hauerf44d6302009-04-15 03:11:30 +0000285 struct fec_enet_private *fep = netdev_priv(dev);
Sascha Hauer2e285322009-04-15 01:32:16 +0000286 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000287 unsigned short status;
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000288 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (!fep->link) {
291 /* Link is down or autonegotiation is in progress. */
292 return 1;
293 }
294
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000295 spin_lock_irqsave(&fep->hw_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 /* Fill in a Tx ring entry */
297 bdp = fep->cur_tx;
298
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000299 status = bdp->cbd_sc;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000300
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000301 if (status & BD_ENET_TX_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 /* Ooops. All transmit buffers are full. Bail out.
303 * This should not happen, since dev->tbusy should be set.
304 */
305 printk("%s: tx queue full!.\n", dev->name);
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000306 spin_unlock_irqrestore(&fep->hw_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return 1;
308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Sascha Hauer22f6b862009-04-15 01:32:18 +0000310 /* Clear all of the status flags */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000311 status &= ~BD_ENET_TX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Sascha Hauer22f6b862009-04-15 01:32:18 +0000313 /* Set buffer length and buffer pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 bdp->cbd_bufaddr = __pa(skb->data);
315 bdp->cbd_datlen = skb->len;
316
317 /*
Sascha Hauer22f6b862009-04-15 01:32:18 +0000318 * On some FEC implementations data must be aligned on
319 * 4-byte boundaries. Use bounce buffers to copy data
320 * and get it aligned. Ugh.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 */
Sascha Hauer196719e2009-01-28 23:03:10 +0000322 if (bdp->cbd_bufaddr & FEC_ALIGNMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 unsigned int index;
324 index = bdp - fep->tx_bd_base;
Sascha Hauer6989f512009-01-28 23:03:06 +0000325 memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
327 }
328
Sascha Hauer22f6b862009-04-15 01:32:18 +0000329 /* Save skb pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 fep->tx_skbuff[fep->skb_cur] = skb;
331
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700332 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /* Push the data cache so the CPM does not get stale memory
336 * data.
337 */
Sascha Hauerccdc4f12009-01-28 23:03:09 +0000338 dma_sync_single(NULL, bdp->cbd_bufaddr,
339 bdp->cbd_datlen, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000341 /* 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000344 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000346 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 dev->trans_start = jiffies;
349
350 /* Trigger transmission start */
Sascha Hauerf44d6302009-04-15 03:11:30 +0000351 writel(0, fep->hwp + FEC_X_DES_ACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Sascha Hauer22f6b862009-04-15 01:32:18 +0000353 /* If this was the last BD in the ring, start at the beginning again. */
354 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 bdp = fep->tx_bd_base;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000356 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 bdp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 if (bdp == fep->dirty_tx) {
360 fep->tx_full = 1;
361 netif_stop_queue(dev);
362 }
363
Sascha Hauer2e285322009-04-15 01:32:16 +0000364 fep->cur_tx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000366 spin_unlock_irqrestore(&fep->hw_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 return 0;
369}
370
371static void
372fec_timeout(struct net_device *dev)
373{
374 struct fec_enet_private *fep = netdev_priv(dev);
375
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700376 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000378 fec_restart(dev, fep->full_duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 netif_wake_queue(dev);
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100383fec_enet_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 struct net_device *dev = dev_id;
Sascha Hauerf44d6302009-04-15 03:11:30 +0000386 struct fec_enet_private *fep = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 uint int_events;
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000388 irqreturn_t ret = IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000390 do {
Sascha Hauerf44d6302009-04-15 03:11:30 +0000391 int_events = readl(fep->hwp + FEC_IEVENT);
392 writel(int_events, fep->hwp + FEC_IEVENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (int_events & FEC_ENET_RXF) {
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000395 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 fec_enet_rx(dev);
397 }
398
399 /* Transmit OK, or non-fatal error. Update the buffer
Sascha Hauerf44d6302009-04-15 03:11:30 +0000400 * descriptors. FEC handles all errors, we just discover
401 * them as part of the transmit process.
402 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (int_events & FEC_ENET_TXF) {
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000404 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 fec_enet_tx(dev);
406 }
407
408 if (int_events & FEC_ENET_MII) {
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000409 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 fec_enet_mii(dev);
411 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400412
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000413 } while (int_events);
414
415 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
418
419static void
420fec_enet_tx(struct net_device *dev)
421{
422 struct fec_enet_private *fep;
Sascha Hauer2e285322009-04-15 01:32:16 +0000423 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000424 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 struct sk_buff *skb;
426
427 fep = netdev_priv(dev);
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000428 spin_lock_irq(&fep->hw_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 bdp = fep->dirty_tx;
430
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000431 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (bdp == fep->cur_tx && fep->tx_full == 0) break;
433
434 skb = fep->tx_skbuff[fep->skb_dirty];
435 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000436 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 BD_ENET_TX_RL | BD_ENET_TX_UN |
438 BD_ENET_TX_CSL)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700439 dev->stats.tx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000440 if (status & BD_ENET_TX_HB) /* No heartbeat */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700441 dev->stats.tx_heartbeat_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000442 if (status & BD_ENET_TX_LC) /* Late collision */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700443 dev->stats.tx_window_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000444 if (status & BD_ENET_TX_RL) /* Retrans limit */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700445 dev->stats.tx_aborted_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000446 if (status & BD_ENET_TX_UN) /* Underrun */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700447 dev->stats.tx_fifo_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000448 if (status & BD_ENET_TX_CSL) /* Carrier lost */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700449 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700451 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000454 if (status & BD_ENET_TX_READY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 printk("HEY! Enet xmit interrupt and TX_READY.\n");
Sascha Hauer22f6b862009-04-15 01:32:18 +0000456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /* Deferred means some collisions occurred during transmit,
458 * but we eventually sent the packet OK.
459 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000460 if (status & BD_ENET_TX_DEF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700461 dev->stats.collisions++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400462
Sascha Hauer22f6b862009-04-15 01:32:18 +0000463 /* Free the sk buffer associated with this last transmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 dev_kfree_skb_any(skb);
465 fep->tx_skbuff[fep->skb_dirty] = NULL;
466 fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400467
Sascha Hauer22f6b862009-04-15 01:32:18 +0000468 /* Update pointer to next buffer descriptor to be transmitted */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000469 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 bdp = fep->tx_bd_base;
471 else
472 bdp++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400473
Sascha Hauer22f6b862009-04-15 01:32:18 +0000474 /* Since we have freed up a buffer, the ring is no longer full
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 */
476 if (fep->tx_full) {
477 fep->tx_full = 0;
478 if (netif_queue_stopped(dev))
479 netif_wake_queue(dev);
480 }
481 }
Sascha Hauer2e285322009-04-15 01:32:16 +0000482 fep->dirty_tx = bdp;
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000483 spin_unlock_irq(&fep->hw_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
486
487/* During a receive, the cur_rx points to the current incoming buffer.
488 * When we update through the ring, if the next incoming buffer has
489 * not been given to the system, we just set the empty indicator,
490 * effectively tossing the packet.
491 */
492static void
493fec_enet_rx(struct net_device *dev)
494{
Sascha Hauerf44d6302009-04-15 03:11:30 +0000495 struct fec_enet_private *fep = netdev_priv(dev);
Sascha Hauer2e285322009-04-15 01:32:16 +0000496 struct bufdesc *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000497 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 struct sk_buff *skb;
499 ushort pkt_len;
500 __u8 *data;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400501
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000502#ifdef CONFIG_M532x
503 flush_cache_all();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000506 spin_lock_irq(&fep->hw_lock);
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /* First, grab all of the stats for the incoming packet.
509 * These get messed up if we get called due to a busy condition.
510 */
511 bdp = fep->cur_rx;
512
Sascha Hauer22f6b862009-04-15 01:32:18 +0000513 while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Sascha Hauer22f6b862009-04-15 01:32:18 +0000515 /* Since we have allocated space to hold a complete frame,
516 * the last indicator should be set.
517 */
518 if ((status & BD_ENET_RX_LAST) == 0)
519 printk("FEC ENET: rcv is not +last\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Sascha Hauer22f6b862009-04-15 01:32:18 +0000521 if (!fep->opened)
522 goto rx_processing_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Sascha Hauer22f6b862009-04-15 01:32:18 +0000524 /* Check for errors. */
525 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
Sascha Hauer22f6b862009-04-15 01:32:18 +0000527 dev->stats.rx_errors++;
528 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
529 /* Frame too long or too short. */
530 dev->stats.rx_length_errors++;
531 }
532 if (status & BD_ENET_RX_NO) /* Frame alignment */
533 dev->stats.rx_frame_errors++;
534 if (status & BD_ENET_RX_CR) /* CRC Error */
535 dev->stats.rx_crc_errors++;
536 if (status & BD_ENET_RX_OV) /* FIFO overrun */
537 dev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
Sascha Hauer22f6b862009-04-15 01:32:18 +0000539
540 /* Report late collisions as a frame error.
541 * On this error, the BD is closed, but we don't know what we
542 * have in the buffer. So, just drop this frame on the floor.
543 */
544 if (status & BD_ENET_RX_CL) {
545 dev->stats.rx_errors++;
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700546 dev->stats.rx_frame_errors++;
Sascha Hauer22f6b862009-04-15 01:32:18 +0000547 goto rx_processing_done;
548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Sascha Hauer22f6b862009-04-15 01:32:18 +0000550 /* Process the incoming frame. */
551 dev->stats.rx_packets++;
552 pkt_len = bdp->cbd_datlen;
553 dev->stats.rx_bytes += pkt_len;
554 data = (__u8*)__va(bdp->cbd_bufaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Sascha Hauer22f6b862009-04-15 01:32:18 +0000556 dma_sync_single(NULL, (unsigned long)__pa(data),
Sascha Hauerccdc4f12009-01-28 23:03:09 +0000557 pkt_len - 4, DMA_FROM_DEVICE);
558
Sascha Hauer22f6b862009-04-15 01:32:18 +0000559 /* This does 16 byte alignment, exactly what we need.
560 * The packet length includes FCS, but we don't want to
561 * include that when passing upstream as it messes up
562 * bridging applications.
563 */
Sascha Hauer85498892009-04-15 01:32:21 +0000564 skb = dev_alloc_skb(pkt_len - 4 + NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Sascha Hauer85498892009-04-15 01:32:21 +0000566 if (unlikely(!skb)) {
Sascha Hauer22f6b862009-04-15 01:32:18 +0000567 printk("%s: Memory squeeze, dropping packet.\n",
568 dev->name);
569 dev->stats.rx_dropped++;
570 } else {
Sascha Hauer85498892009-04-15 01:32:21 +0000571 skb_reserve(skb, NET_IP_ALIGN);
Sascha Hauer22f6b862009-04-15 01:32:18 +0000572 skb_put(skb, pkt_len - 4); /* Make room */
573 skb_copy_to_linear_data(skb, data, pkt_len - 4);
574 skb->protocol = eth_type_trans(skb, dev);
575 netif_rx(skb);
576 }
577rx_processing_done:
578 /* Clear the status flags for this buffer */
579 status &= ~BD_ENET_RX_STATS;
580
581 /* Mark the buffer empty */
582 status |= BD_ENET_RX_EMPTY;
583 bdp->cbd_sc = status;
584
585 /* Update BD pointer to next entry */
586 if (status & BD_ENET_RX_WRAP)
587 bdp = fep->rx_bd_base;
588 else
589 bdp++;
590 /* Doing this here will keep the FEC running while we process
591 * incoming frames. On a heavily loaded network, we should be
592 * able to keep up at the expense of system resources.
593 */
594 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
Sascha Hauer2e285322009-04-15 01:32:16 +0000596 fep->cur_rx = bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000598 spin_unlock_irq(&fep->hw_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000601/* called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602static void
603fec_enet_mii(struct net_device *dev)
604{
605 struct fec_enet_private *fep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 mii_list_t *mip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 fep = netdev_priv(dev);
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000609 spin_lock_irq(&fep->mii_lock);
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if ((mip = mii_head) == NULL) {
612 printk("MII and no head!\n");
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000613 goto unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
616 if (mip->mii_func != NULL)
Sascha Hauerf44d6302009-04-15 03:11:30 +0000617 (*(mip->mii_func))(readl(fep->hwp + FEC_MII_DATA), dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 mii_head = mip->mii_next;
620 mip->mii_next = mii_free;
621 mii_free = mip;
622
623 if ((mip = mii_head) != NULL)
Sascha Hauerf44d6302009-04-15 03:11:30 +0000624 writel(mip->mii_regval, fep->hwp + FEC_MII_DATA);
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000625
626unlock:
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000627 spin_unlock_irq(&fep->mii_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
630static int
631mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
632{
633 struct fec_enet_private *fep;
634 unsigned long flags;
635 mii_list_t *mip;
636 int retval;
637
Sascha Hauer22f6b862009-04-15 01:32:18 +0000638 /* Add PHY address to register command */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 fep = netdev_priv(dev);
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000640 spin_lock_irqsave(&fep->mii_lock, flags);
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 regval |= fep->phy_addr << 23;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 retval = 0;
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if ((mip = mii_free) != NULL) {
646 mii_free = mip->mii_next;
647 mip->mii_regval = regval;
648 mip->mii_func = func;
649 mip->mii_next = NULL;
650 if (mii_head) {
651 mii_tail->mii_next = mip;
652 mii_tail = mip;
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000653 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 mii_head = mii_tail = mip;
Sascha Hauerf44d6302009-04-15 03:11:30 +0000655 writel(regval, fep->hwp + FEC_MII_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000657 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 retval = 1;
659 }
660
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +1000661 spin_unlock_irqrestore(&fep->mii_lock, flags);
662 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
665static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
666{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if(!c)
668 return;
669
Philippe De Muyterbe6cb662007-10-23 14:37:54 +1000670 for (; c->mii_data != mk_mii_end; c++)
671 mii_queue(dev, c->mii_data, c->funct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674static void mii_parse_sr(uint mii_reg, struct net_device *dev)
675{
676 struct fec_enet_private *fep = netdev_priv(dev);
677 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000678 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000680 status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 if (mii_reg & 0x0004)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000683 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 if (mii_reg & 0x0010)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000685 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000687 status |= PHY_STAT_ANC;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000688 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691static void mii_parse_cr(uint mii_reg, struct net_device *dev)
692{
693 struct fec_enet_private *fep = netdev_priv(dev);
694 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000695 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000697 status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000700 status |= PHY_CONF_ANE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 if (mii_reg & 0x4000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000702 status |= PHY_CONF_LOOP;
703 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
705
706static void mii_parse_anar(uint mii_reg, struct net_device *dev)
707{
708 struct fec_enet_private *fep = netdev_priv(dev);
709 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000710 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000712 status = *s & ~(PHY_CONF_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
714 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000715 status |= PHY_CONF_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (mii_reg & 0x0040)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000717 status |= PHY_CONF_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000719 status |= PHY_CONF_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (mii_reg & 0x00100)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000721 status |= PHY_CONF_100FDX;
722 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723}
724
725/* ------------------------------------------------------------------------- */
726/* The Level one LXT970 is used by many boards */
727
728#define MII_LXT970_MIRROR 16 /* Mirror register */
729#define MII_LXT970_IER 17 /* Interrupt Enable Register */
730#define MII_LXT970_ISR 18 /* Interrupt Status Register */
731#define MII_LXT970_CONFIG 19 /* Configuration Register */
732#define MII_LXT970_CSR 20 /* Chip Status Register */
733
734static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
735{
736 struct fec_enet_private *fep = netdev_priv(dev);
737 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000738 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000740 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 if (mii_reg & 0x0800) {
742 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000743 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000745 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 } else {
747 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000748 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000750 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000752 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000755static phy_cmd_t const phy_cmd_lxt970_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 { mk_mii_read(MII_REG_CR), mii_parse_cr },
757 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
758 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000759 };
760static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
762 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
763 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000764 };
765static phy_cmd_t const phy_cmd_lxt970_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 /* read SR and ISR to acknowledge */
767 { mk_mii_read(MII_REG_SR), mii_parse_sr },
768 { mk_mii_read(MII_LXT970_ISR), NULL },
769
770 /* find out the current status */
771 { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
772 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000773 };
774static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
776 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000777 };
778static phy_info_t const phy_info_lxt970 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400779 .id = 0x07810000,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000780 .name = "LXT970",
781 .config = phy_cmd_lxt970_config,
782 .startup = phy_cmd_lxt970_startup,
783 .ack_int = phy_cmd_lxt970_ack_int,
784 .shutdown = phy_cmd_lxt970_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787/* ------------------------------------------------------------------------- */
788/* The Level one LXT971 is used on some of my custom boards */
789
790/* register definitions for the 971 */
791
792#define MII_LXT971_PCR 16 /* Port Control Register */
793#define MII_LXT971_SR2 17 /* Status Register 2 */
794#define MII_LXT971_IER 18 /* Interrupt Enable Register */
795#define MII_LXT971_ISR 19 /* Interrupt Status Register */
796#define MII_LXT971_LCR 20 /* LED Control Register */
797#define MII_LXT971_TCR 30 /* Transmit Control Register */
798
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400799/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 * I had some nice ideas of running the MDIO faster...
801 * The 971 should support 8MHz and I tried it, but things acted really
802 * weird, so 2.5 MHz ought to be enough for anyone...
803 */
804
805static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
806{
807 struct fec_enet_private *fep = netdev_priv(dev);
808 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000809 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000811 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 if (mii_reg & 0x0400) {
814 fep->link = 1;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000815 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 } else {
817 fep->link = 0;
818 }
819 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000820 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (mii_reg & 0x4000) {
822 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000823 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000825 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 } else {
827 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000828 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000830 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832 if (mii_reg & 0x0008)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000833 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000835 *s = status;
836}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400837
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000838static phy_cmd_t const phy_cmd_lxt971_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400839 /* limit to 10MBit because my prototype board
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 * doesn't work with 100. */
841 { mk_mii_read(MII_REG_CR), mii_parse_cr },
842 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
843 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
844 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000845 };
846static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
848 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
849 { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */
850 /* Somehow does the 971 tell me that the link is down
851 * the first read after power-up.
852 * read here to get a valid value in ack_int */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400853 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000855 };
856static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
857 /* acknowledge the int before reading status ! */
858 { mk_mii_read(MII_LXT971_ISR), NULL },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 /* find out the current status */
860 { mk_mii_read(MII_REG_SR), mii_parse_sr },
861 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000863 };
864static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
866 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000867 };
868static phy_info_t const phy_info_lxt971 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400869 .id = 0x0001378e,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000870 .name = "LXT971",
871 .config = phy_cmd_lxt971_config,
872 .startup = phy_cmd_lxt971_startup,
873 .ack_int = phy_cmd_lxt971_ack_int,
874 .shutdown = phy_cmd_lxt971_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875};
876
877/* ------------------------------------------------------------------------- */
878/* The Quality Semiconductor QS6612 is used on the RPX CLLF */
879
880/* register definitions */
881
882#define MII_QS6612_MCR 17 /* Mode Control Register */
883#define MII_QS6612_FTR 27 /* Factory Test Register */
884#define MII_QS6612_MCO 28 /* Misc. Control Register */
885#define MII_QS6612_ISR 29 /* Interrupt Source Register */
886#define MII_QS6612_IMR 30 /* Interrupt Mask Register */
887#define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
888
889static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
890{
891 struct fec_enet_private *fep = netdev_priv(dev);
892 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000893 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000895 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 switch((mii_reg >> 2) & 7) {
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000898 case 1: status |= PHY_STAT_10HDX; break;
899 case 2: status |= PHY_STAT_100HDX; break;
900 case 5: status |= PHY_STAT_10FDX; break;
901 case 6: status |= PHY_STAT_100FDX; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000904 *s = status;
905}
906
907static phy_cmd_t const phy_cmd_qs6612_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400908 /* The PHY powers up isolated on the RPX,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 * so send a command to allow operation.
910 */
911 { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
912
913 /* parse cr and anar to get some info */
914 { mk_mii_read(MII_REG_CR), mii_parse_cr },
915 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
916 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000917 };
918static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
920 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
921 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000922 };
923static phy_cmd_t const phy_cmd_qs6612_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 /* we need to read ISR, SR and ANER to acknowledge */
925 { mk_mii_read(MII_QS6612_ISR), NULL },
926 { mk_mii_read(MII_REG_SR), mii_parse_sr },
927 { mk_mii_read(MII_REG_ANER), NULL },
928
929 /* read pcr to get info */
930 { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
931 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000932 };
933static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
935 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000936 };
937static phy_info_t const phy_info_qs6612 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400938 .id = 0x00181440,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000939 .name = "QS6612",
940 .config = phy_cmd_qs6612_config,
941 .startup = phy_cmd_qs6612_startup,
942 .ack_int = phy_cmd_qs6612_ack_int,
943 .shutdown = phy_cmd_qs6612_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944};
945
946/* ------------------------------------------------------------------------- */
947/* AMD AM79C874 phy */
948
949/* register definitions for the 874 */
950
951#define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
952#define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
953#define MII_AM79C874_DR 18 /* Diagnostic Register */
954#define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
955#define MII_AM79C874_MCR 21 /* ModeControl Register */
956#define MII_AM79C874_DC 23 /* Disconnect Counter */
957#define MII_AM79C874_REC 24 /* Recieve Error Counter */
958
959static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev)
960{
961 struct fec_enet_private *fep = netdev_priv(dev);
962 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000963 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000965 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000968 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (mii_reg & 0x0400)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000970 status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000972 status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
973
974 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000977static phy_cmd_t const phy_cmd_am79c874_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 { mk_mii_read(MII_REG_CR), mii_parse_cr },
979 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
980 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
981 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000982 };
983static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
985 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400986 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000988 };
989static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 /* find out the current status */
991 { mk_mii_read(MII_REG_SR), mii_parse_sr },
992 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
993 /* we only need to read ISR to acknowledge */
994 { mk_mii_read(MII_AM79C874_ICSR), NULL },
995 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000996 };
997static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL },
999 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001000 };
1001static phy_info_t const phy_info_am79c874 = {
1002 .id = 0x00022561,
1003 .name = "AM79C874",
1004 .config = phy_cmd_am79c874_config,
1005 .startup = phy_cmd_am79c874_startup,
1006 .ack_int = phy_cmd_am79c874_ack_int,
1007 .shutdown = phy_cmd_am79c874_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008};
1009
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011/* ------------------------------------------------------------------------- */
1012/* Kendin KS8721BL phy */
1013
1014/* register definitions for the 8721 */
1015
1016#define MII_KS8721BL_RXERCR 21
Sascha Hauer43268dc2009-01-28 23:03:08 +00001017#define MII_KS8721BL_ICSR 27
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018#define MII_KS8721BL_PHYCR 31
1019
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001020static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1022 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1023 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001024 };
1025static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
1027 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001028 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001030 };
1031static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 /* find out the current status */
1033 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1034 /* we only need to read ISR to acknowledge */
1035 { mk_mii_read(MII_KS8721BL_ICSR), NULL },
1036 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001037 };
1038static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL },
1040 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001041 };
1042static phy_info_t const phy_info_ks8721bl = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001043 .id = 0x00022161,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001044 .name = "KS8721BL",
1045 .config = phy_cmd_ks8721bl_config,
1046 .startup = phy_cmd_ks8721bl_startup,
1047 .ack_int = phy_cmd_ks8721bl_ack_int,
1048 .shutdown = phy_cmd_ks8721bl_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049};
1050
1051/* ------------------------------------------------------------------------- */
Greg Ungerer562d2f82005-11-07 14:09:50 +10001052/* register definitions for the DP83848 */
1053
1054#define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
1055
1056static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
1057{
Wang Chen4cf16532008-11-12 23:38:14 -08001058 struct fec_enet_private *fep = netdev_priv(dev);
Greg Ungerer562d2f82005-11-07 14:09:50 +10001059 volatile uint *s = &(fep->phy_status);
1060
1061 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
1062
1063 /* Link up */
1064 if (mii_reg & 0x0001) {
1065 fep->link = 1;
1066 *s |= PHY_STAT_LINK;
1067 } else
1068 fep->link = 0;
1069 /* Status of link */
1070 if (mii_reg & 0x0010) /* Autonegotioation complete */
1071 *s |= PHY_STAT_ANC;
1072 if (mii_reg & 0x0002) { /* 10MBps? */
1073 if (mii_reg & 0x0004) /* Full Duplex? */
1074 *s |= PHY_STAT_10FDX;
1075 else
1076 *s |= PHY_STAT_10HDX;
1077 } else { /* 100 Mbps? */
1078 if (mii_reg & 0x0004) /* Full Duplex? */
1079 *s |= PHY_STAT_100FDX;
1080 else
1081 *s |= PHY_STAT_100HDX;
1082 }
1083 if (mii_reg & 0x0008)
1084 *s |= PHY_STAT_FAULT;
1085}
1086
1087static phy_info_t phy_info_dp83848= {
1088 0x020005c9,
1089 "DP83848",
1090
1091 (const phy_cmd_t []) { /* config */
1092 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1093 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1094 { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
1095 { mk_mii_end, }
1096 },
1097 (const phy_cmd_t []) { /* startup - enable interrupts */
1098 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1099 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1100 { mk_mii_end, }
1101 },
1102 (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
1103 { mk_mii_end, }
1104 },
1105 (const phy_cmd_t []) { /* shutdown */
1106 { mk_mii_end, }
1107 },
1108};
1109
1110/* ------------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001112static phy_info_t const * const phy_info[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 &phy_info_lxt970,
1114 &phy_info_lxt971,
1115 &phy_info_qs6612,
1116 &phy_info_am79c874,
1117 &phy_info_ks8721bl,
Greg Ungerer562d2f82005-11-07 14:09:50 +10001118 &phy_info_dp83848,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 NULL
1120};
1121
1122/* ------------------------------------------------------------------------- */
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10001123#ifdef HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001125mii_link_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127/*
Greg Ungerer43be6362009-02-26 22:42:51 -08001128 * This is specific to the MII interrupt setup of the M5272EVB.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 */
Greg Ungerer43be6362009-02-26 22:42:51 -08001130static void __inline__ fec_request_mii_intr(struct net_device *dev)
1131{
1132 if (request_irq(66, mii_link_interrupt, IRQF_DISABLED, "fec(MII)", dev) != 0)
1133 printk("FEC: Could not allocate fec(MII) IRQ(66)!\n");
1134}
1135
1136static void __inline__ fec_disable_phy_intr(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
1138 volatile unsigned long *icrp;
Greg Ungerer43be6362009-02-26 22:42:51 -08001139 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
1140 *icrp = 0x08000000;
1141}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Greg Ungerer43be6362009-02-26 22:42:51 -08001143static void __inline__ fec_phy_ack_intr(void)
1144{
1145 volatile unsigned long *icrp;
1146 /* Acknowledge the interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001148 *icrp = 0x0d000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Greg Ungerer43be6362009-02-26 22:42:51 -08001151#ifdef CONFIG_M5272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152static void __inline__ fec_get_mac(struct net_device *dev)
1153{
1154 struct fec_enet_private *fep = netdev_priv(dev);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001155 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001157 if (FEC_FLASHMAC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /*
1159 * Get MAC address from FLASH.
1160 * If it is all 1's or 0's, use the default.
1161 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001162 iap = (unsigned char *)FEC_FLASHMAC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1164 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1165 iap = fec_mac_default;
1166 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1167 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1168 iap = fec_mac_default;
1169 } else {
Sascha Hauerf44d6302009-04-15 03:11:30 +00001170 *((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW);
1171 *((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 iap = &tmpaddr[0];
1173 }
1174
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001175 memcpy(dev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 /* Adjust MAC if using default MAC address */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001178 if (iap == fec_mac_default)
1179 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181#endif
1182
1183/* ------------------------------------------------------------------------- */
1184
1185static void mii_display_status(struct net_device *dev)
1186{
1187 struct fec_enet_private *fep = netdev_priv(dev);
1188 volatile uint *s = &(fep->phy_status);
1189
1190 if (!fep->link && !fep->old_link) {
1191 /* Link is still down - don't print anything */
1192 return;
1193 }
1194
1195 printk("%s: status: ", dev->name);
1196
1197 if (!fep->link) {
1198 printk("link down");
1199 } else {
1200 printk("link up");
1201
1202 switch(*s & PHY_STAT_SPMASK) {
1203 case PHY_STAT_100FDX: printk(", 100MBit Full Duplex"); break;
1204 case PHY_STAT_100HDX: printk(", 100MBit Half Duplex"); break;
1205 case PHY_STAT_10FDX: printk(", 10MBit Full Duplex"); break;
1206 case PHY_STAT_10HDX: printk(", 10MBit Half Duplex"); break;
1207 default:
1208 printk(", Unknown speed/duplex");
1209 }
1210
1211 if (*s & PHY_STAT_ANC)
1212 printk(", auto-negotiation complete");
1213 }
1214
1215 if (*s & PHY_STAT_FAULT)
1216 printk(", remote fault");
1217
1218 printk(".\n");
1219}
1220
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001221static void mii_display_config(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001223 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
1224 struct net_device *dev = fep->netdev;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001225 uint status = fep->phy_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 /*
1228 ** When we get here, phy_task is already removed from
1229 ** the workqueue. It is thus safe to allow to reuse it.
1230 */
1231 fep->mii_phy_task_queued = 0;
1232 printk("%s: config: auto-negotiation ", dev->name);
1233
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001234 if (status & PHY_CONF_ANE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 printk("on");
1236 else
1237 printk("off");
1238
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001239 if (status & PHY_CONF_100FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 printk(", 100FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001241 if (status & PHY_CONF_100HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 printk(", 100HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001243 if (status & PHY_CONF_10FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 printk(", 10FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001245 if (status & PHY_CONF_10HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 printk(", 10HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001247 if (!(status & PHY_CONF_SPMASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 printk(", No speed/duplex selected?");
1249
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001250 if (status & PHY_CONF_LOOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 printk(", loopback enabled");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 printk(".\n");
1254
1255 fep->sequence_done = 1;
1256}
1257
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001258static void mii_relink(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001260 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
1261 struct net_device *dev = fep->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 int duplex;
1263
1264 /*
1265 ** When we get here, phy_task is already removed from
1266 ** the workqueue. It is thus safe to allow to reuse it.
1267 */
1268 fep->mii_phy_task_queued = 0;
1269 fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
1270 mii_display_status(dev);
1271 fep->old_link = fep->link;
1272
1273 if (fep->link) {
1274 duplex = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001275 if (fep->phy_status
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 & (PHY_STAT_100FDX | PHY_STAT_10FDX))
1277 duplex = 1;
1278 fec_restart(dev, duplex);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10001279 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 fec_stop(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
1283/* mii_queue_relink is called in interrupt context from mii_link_interrupt */
1284static void mii_queue_relink(uint mii_reg, struct net_device *dev)
1285{
1286 struct fec_enet_private *fep = netdev_priv(dev);
1287
1288 /*
Sascha Hauer22f6b862009-04-15 01:32:18 +00001289 * We cannot queue phy_task twice in the workqueue. It
1290 * would cause an endless loop in the workqueue.
1291 * Fortunately, if the last mii_relink entry has not yet been
1292 * executed now, it will do the job for the current interrupt,
1293 * which is just what we want.
1294 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (fep->mii_phy_task_queued)
1296 return;
1297
1298 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001299 INIT_WORK(&fep->phy_task, mii_relink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 schedule_work(&fep->phy_task);
1301}
1302
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001303/* mii_queue_config is called in interrupt context from fec_enet_mii */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304static void mii_queue_config(uint mii_reg, struct net_device *dev)
1305{
1306 struct fec_enet_private *fep = netdev_priv(dev);
1307
1308 if (fep->mii_phy_task_queued)
1309 return;
1310
1311 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001312 INIT_WORK(&fep->phy_task, mii_display_config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 schedule_work(&fep->phy_task);
1314}
1315
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001316phy_cmd_t const phy_cmd_relink[] = {
1317 { mk_mii_read(MII_REG_CR), mii_queue_relink },
1318 { mk_mii_end, }
1319 };
1320phy_cmd_t const phy_cmd_config[] = {
1321 { mk_mii_read(MII_REG_CR), mii_queue_config },
1322 { mk_mii_end, }
1323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Sascha Hauer22f6b862009-04-15 01:32:18 +00001325/* Read remainder of PHY ID. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326static void
1327mii_discover_phy3(uint mii_reg, struct net_device *dev)
1328{
1329 struct fec_enet_private *fep;
1330 int i;
1331
1332 fep = netdev_priv(dev);
1333 fep->phy_id |= (mii_reg & 0xffff);
1334 printk("fec: PHY @ 0x%x, ID 0x%08x", fep->phy_addr, fep->phy_id);
1335
1336 for(i = 0; phy_info[i]; i++) {
1337 if(phy_info[i]->id == (fep->phy_id >> 4))
1338 break;
1339 }
1340
1341 if (phy_info[i])
1342 printk(" -- %s\n", phy_info[i]->name);
1343 else
1344 printk(" -- unknown PHY!\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 fep->phy = phy_info[i];
1347 fep->phy_id_done = 1;
1348}
1349
1350/* Scan all of the MII PHY addresses looking for someone to respond
1351 * with a valid ID. This usually happens quickly.
1352 */
1353static void
1354mii_discover_phy(uint mii_reg, struct net_device *dev)
1355{
1356 struct fec_enet_private *fep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 uint phytype;
1358
1359 fep = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 if (fep->phy_addr < 32) {
1362 if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001363
Sascha Hauer22f6b862009-04-15 01:32:18 +00001364 /* Got first part of ID, now get remainder */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 fep->phy_id = phytype << 16;
1366 mii_queue(dev, mk_mii_read(MII_REG_PHYIR2),
1367 mii_discover_phy3);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10001368 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 fep->phy_addr++;
1370 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1),
1371 mii_discover_phy);
1372 }
1373 } else {
1374 printk("FEC: No PHY device found.\n");
1375 /* Disable external MII interface */
Sascha Hauerf44d6302009-04-15 03:11:30 +00001376 writel(0, fep->hwp + FEC_MII_SPEED);
1377 fep->phy_speed = 0;
Greg Ungerer43be6362009-02-26 22:42:51 -08001378#ifdef HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 fec_disable_phy_intr();
Sascha Haueread73182009-01-28 23:03:11 +00001380#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382}
1383
Sascha Hauer22f6b862009-04-15 01:32:18 +00001384/* This interrupt occurs when the PHY detects a link change */
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10001385#ifdef HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001387mii_link_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 struct net_device *dev = dev_id;
1390 struct fec_enet_private *fep = netdev_priv(dev);
1391
1392 fec_phy_ack_intr();
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 mii_do_cmd(dev, fep->phy->ack_int);
1395 mii_do_cmd(dev, phy_cmd_relink); /* restart and display status */
1396
1397 return IRQ_HANDLED;
1398}
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10001399#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
1401static int
1402fec_enet_open(struct net_device *dev)
1403{
1404 struct fec_enet_private *fep = netdev_priv(dev);
1405
1406 /* I should reset the ring buffers here, but I don't yet know
1407 * a simple way to do that.
1408 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 fep->sequence_done = 0;
1411 fep->link = 0;
1412
1413 if (fep->phy) {
1414 mii_do_cmd(dev, fep->phy->ack_int);
1415 mii_do_cmd(dev, fep->phy->config);
1416 mii_do_cmd(dev, phy_cmd_config); /* display configuration */
1417
Matt Waddel6b265292006-06-27 13:10:56 +10001418 /* Poll until the PHY tells us its configuration
1419 * (not link state).
1420 * Request is initiated by mii_do_cmd above, but answer
1421 * comes by interrupt.
1422 * This should take about 25 usec per register at 2.5 MHz,
1423 * and we read approximately 5 registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 */
1425 while(!fep->sequence_done)
1426 schedule();
1427
1428 mii_do_cmd(dev, fep->phy->startup);
1429
1430 /* Set the initial link state to true. A lot of hardware
1431 * based on this device does not implement a PHY interrupt,
1432 * so we are never notified of link change.
1433 */
1434 fep->link = 1;
1435 } else {
1436 fep->link = 1; /* lets just try it and see */
1437 /* no phy, go full duplex, it's most likely a hub chip */
1438 fec_restart(dev, 1);
1439 }
1440
1441 netif_start_queue(dev);
1442 fep->opened = 1;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001443 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
1446static int
1447fec_enet_close(struct net_device *dev)
1448{
1449 struct fec_enet_private *fep = netdev_priv(dev);
1450
Sascha Hauer22f6b862009-04-15 01:32:18 +00001451 /* Don't know what to do yet. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 fep->opened = 0;
1453 netif_stop_queue(dev);
1454 fec_stop(dev);
1455
1456 return 0;
1457}
1458
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459/* Set or clear the multicast filter for this adaptor.
1460 * Skeleton taken from sunlance driver.
1461 * The CPM Ethernet implementation allows Multicast as well as individual
1462 * MAC address filtering. Some of the drivers check to make sure it is
1463 * a group multicast address, and discard those that are not. I guess I
1464 * will do the same for now, but just remove the test if you want
1465 * individual filtering as well (do the upper net layers want or support
1466 * this kind of feature?).
1467 */
1468
1469#define HASH_BITS 6 /* #bits in hash */
1470#define CRC32_POLY 0xEDB88320
1471
1472static void set_multicast_list(struct net_device *dev)
1473{
Sascha Hauerf44d6302009-04-15 03:11:30 +00001474 struct fec_enet_private *fep = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 struct dev_mc_list *dmi;
Sascha Hauerf44d6302009-04-15 03:11:30 +00001476 unsigned int i, j, bit, data, crc, tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 unsigned char hash;
1478
Sascha Hauer22f6b862009-04-15 01:32:18 +00001479 if (dev->flags & IFF_PROMISC) {
Sascha Hauerf44d6302009-04-15 03:11:30 +00001480 tmp = readl(fep->hwp + FEC_R_CNTRL);
1481 tmp |= 0x8;
1482 writel(tmp, fep->hwp + FEC_R_CNTRL);
Sascha Hauer4e831832009-04-15 01:32:19 +00001483 return;
1484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Sascha Hauer4e831832009-04-15 01:32:19 +00001486 tmp = readl(fep->hwp + FEC_R_CNTRL);
1487 tmp &= ~0x8;
1488 writel(tmp, fep->hwp + FEC_R_CNTRL);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001489
Sascha Hauer4e831832009-04-15 01:32:19 +00001490 if (dev->flags & IFF_ALLMULTI) {
1491 /* Catch all multicast addresses, so set the
1492 * filter to all 1's
1493 */
1494 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1495 writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Sascha Hauer4e831832009-04-15 01:32:19 +00001497 return;
1498 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001499
Sascha Hauer4e831832009-04-15 01:32:19 +00001500 /* Clear filter and add the addresses in hash register
1501 */
1502 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1503 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Sascha Hauer4e831832009-04-15 01:32:19 +00001505 dmi = dev->mc_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Sascha Hauer4e831832009-04-15 01:32:19 +00001507 for (j = 0; j < dev->mc_count; j++, dmi = dmi->next) {
1508 /* Only support group multicast for now */
1509 if (!(dmi->dmi_addr[0] & 1))
1510 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001511
Sascha Hauer4e831832009-04-15 01:32:19 +00001512 /* calculate crc32 value of mac address */
1513 crc = 0xffffffff;
1514
1515 for (i = 0; i < dmi->dmi_addrlen; i++) {
1516 data = dmi->dmi_addr[i];
1517 for (bit = 0; bit < 8; bit++, data >>= 1) {
1518 crc = (crc >> 1) ^
1519 (((crc ^ data) & 1) ? CRC32_POLY : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
Sascha Hauer4e831832009-04-15 01:32:19 +00001522
1523 /* only upper 6 bits (HASH_BITS) are used
1524 * which point to specific bit in he hash registers
1525 */
1526 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
1527
1528 if (hash > 31) {
1529 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1530 tmp |= 1 << (hash - 32);
1531 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1532 } else {
1533 tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1534 tmp |= 1 << hash;
1535 writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
1536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
1538}
1539
Sascha Hauer22f6b862009-04-15 01:32:18 +00001540/* Set a MAC change in hardware. */
Sascha Hauer009fda82009-04-15 01:32:23 +00001541static int
1542fec_set_mac_address(struct net_device *dev, void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Sascha Hauerf44d6302009-04-15 03:11:30 +00001544 struct fec_enet_private *fep = netdev_priv(dev);
Sascha Hauer009fda82009-04-15 01:32:23 +00001545 struct sockaddr *addr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Sascha Hauer009fda82009-04-15 01:32:23 +00001547 if (!is_valid_ether_addr(addr->sa_data))
1548 return -EADDRNOTAVAIL;
1549
1550 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1551
Sascha Hauerf44d6302009-04-15 03:11:30 +00001552 writel(dev->dev_addr[3] | (dev->dev_addr[2] << 8) |
1553 (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24),
1554 fep->hwp + FEC_ADDR_LOW);
1555 writel((dev->dev_addr[5] << 16) | (dev->dev_addr[4] << 24),
1556 fep + FEC_ADDR_HIGH);
Sascha Hauer009fda82009-04-15 01:32:23 +00001557 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Sascha Hauer009fda82009-04-15 01:32:23 +00001560static const struct net_device_ops fec_netdev_ops = {
1561 .ndo_open = fec_enet_open,
1562 .ndo_stop = fec_enet_close,
1563 .ndo_start_xmit = fec_enet_start_xmit,
1564 .ndo_set_multicast_list = set_multicast_list,
1565 .ndo_validate_addr = eth_validate_addr,
1566 .ndo_tx_timeout = fec_timeout,
1567 .ndo_set_mac_address = fec_set_mac_address,
1568};
1569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 /*
1571 * XXX: We need to clean up on failure exits here.
Sascha Haueread73182009-01-28 23:03:11 +00001572 *
1573 * index is only used in legacy code
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 */
Sascha Haueread73182009-01-28 23:03:11 +00001575int __init fec_enet_init(struct net_device *dev, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
1577 struct fec_enet_private *fep = netdev_priv(dev);
1578 unsigned long mem_addr;
Sascha Hauer2e285322009-04-15 01:32:16 +00001579 struct bufdesc *bdp, *cbd_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00001582 /* Allocate memory for buffer descriptors. */
1583 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
1584 GFP_KERNEL);
1585 if (!cbd_base) {
Greg Ungerer562d2f82005-11-07 14:09:50 +10001586 printk("FEC: allocate descriptor memory failed?\n");
1587 return -ENOMEM;
1588 }
1589
Sebastian Siewior3b2b74c2008-05-01 14:08:12 +10001590 spin_lock_init(&fep->hw_lock);
1591 spin_lock_init(&fep->mii_lock);
1592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 fep->index = index;
Sascha Hauerf44d6302009-04-15 03:11:30 +00001594 fep->hwp = (void __iomem *)dev->base_addr;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001595 fep->netdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Sascha Haueread73182009-01-28 23:03:11 +00001597 /* Set the Ethernet address */
Greg Ungerer43be6362009-02-26 22:42:51 -08001598#ifdef CONFIG_M5272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 fec_get_mac(dev);
Sascha Haueread73182009-01-28 23:03:11 +00001600#else
1601 {
1602 unsigned long l;
Sascha Hauerf44d6302009-04-15 03:11:30 +00001603 l = readl(fep->hwp + FEC_ADDR_LOW);
Sascha Haueread73182009-01-28 23:03:11 +00001604 dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24);
1605 dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16);
1606 dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8);
1607 dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0);
Sascha Hauerf44d6302009-04-15 03:11:30 +00001608 l = readl(fep->hwp + FEC_ADDR_HIGH);
Sascha Haueread73182009-01-28 23:03:11 +00001609 dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24);
1610 dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16);
1611 }
1612#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Sascha Hauer8d4dd5c2009-04-15 01:32:17 +00001614 /* Set receive and transmit descriptor base. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 fep->rx_bd_base = cbd_base;
1616 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
1617
Sascha Hauer22f6b862009-04-15 01:32:18 +00001618 /* Initialize the receive buffer descriptors. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 bdp = fep->rx_bd_base;
1620 for (i=0; i<FEC_ENET_RX_PAGES; i++) {
1621
Sascha Hauer22f6b862009-04-15 01:32:18 +00001622 /* Allocate a page */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 mem_addr = __get_free_page(GFP_KERNEL);
1624 /* XXX: missing check for allocation failure */
1625
Sascha Hauer22f6b862009-04-15 01:32:18 +00001626 /* Initialize the BD for every fragment in the page */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 for (j=0; j<FEC_ENET_RX_FRPPG; j++) {
1628 bdp->cbd_sc = BD_ENET_RX_EMPTY;
1629 bdp->cbd_bufaddr = __pa(mem_addr);
1630 mem_addr += FEC_ENET_RX_FRSIZE;
1631 bdp++;
1632 }
1633 }
1634
Sascha Hauer22f6b862009-04-15 01:32:18 +00001635 /* Set the last buffer to wrap */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 bdp--;
1637 bdp->cbd_sc |= BD_SC_WRAP;
1638
Sascha Hauer22f6b862009-04-15 01:32:18 +00001639 /* ...and the same for transmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 bdp = fep->tx_bd_base;
1641 for (i=0, j=FEC_ENET_TX_FRPPG; i<TX_RING_SIZE; i++) {
1642 if (j >= FEC_ENET_TX_FRPPG) {
1643 mem_addr = __get_free_page(GFP_KERNEL);
1644 j = 1;
1645 } else {
1646 mem_addr += FEC_ENET_TX_FRSIZE;
1647 j++;
1648 }
1649 fep->tx_bounce[i] = (unsigned char *) mem_addr;
1650
Sascha Hauer22f6b862009-04-15 01:32:18 +00001651 /* Initialize the BD for every fragment in the page */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 bdp->cbd_sc = 0;
1653 bdp->cbd_bufaddr = 0;
1654 bdp++;
1655 }
1656
Sascha Hauer22f6b862009-04-15 01:32:18 +00001657 /* Set the last buffer to wrap */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 bdp--;
1659 bdp->cbd_sc |= BD_SC_WRAP;
1660
Greg Ungerer43be6362009-02-26 22:42:51 -08001661#ifdef HAVE_mii_link_interrupt
1662 fec_request_mii_intr(dev);
Sascha Haueread73182009-01-28 23:03:11 +00001663#endif
Sascha Hauer22f6b862009-04-15 01:32:18 +00001664 /* The FEC Ethernet specific entries in the device structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 dev->watchdog_timeo = TX_TIMEOUT;
Sascha Hauer009fda82009-04-15 01:32:23 +00001666 dev->netdev_ops = &fec_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 for (i=0; i<NMII-1; i++)
1669 mii_cmds[i].mii_next = &mii_cmds[i+1];
1670 mii_free = mii_cmds;
1671
Sascha Hauer22f6b862009-04-15 01:32:18 +00001672 /* Set MII speed to 2.5 MHz */
Sascha Haueread73182009-01-28 23:03:11 +00001673 fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
1674 / 2500000) / 2) & 0x3F) << 1;
Sascha Haueread73182009-01-28 23:03:11 +00001675 fec_restart(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 /* Queue up command to detect the PHY and initialize the
1678 * remainder of the interface.
1679 */
1680 fep->phy_id_done = 0;
1681 fep->phy_addr = 0;
1682 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 return 0;
1685}
1686
1687/* This function is called to start or restart the FEC during a link
1688 * change. This only happens when switching between half and full
1689 * duplex.
1690 */
1691static void
1692fec_restart(struct net_device *dev, int duplex)
1693{
Sascha Hauerf44d6302009-04-15 03:11:30 +00001694 struct fec_enet_private *fep = netdev_priv(dev);
Sascha Hauer2e285322009-04-15 01:32:16 +00001695 struct bufdesc *bdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 int i;
1697
Sascha Hauerf44d6302009-04-15 03:11:30 +00001698 /* Whack a reset. We should wait for this. */
1699 writel(1, fep->hwp + FEC_ECNTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 udelay(10);
1701
Sascha Hauerf44d6302009-04-15 03:11:30 +00001702 /* Clear any outstanding interrupt. */
1703 writel(0xffc00000, fep->hwp + FEC_IEVENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Sascha Hauerf44d6302009-04-15 03:11:30 +00001705 /* Reset all multicast. */
1706 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
1707 writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
Sascha Hauer4f1ceb42009-04-15 01:32:20 +00001708#ifndef CONFIG_M5272
1709 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
1710 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
1711#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Sascha Hauerf44d6302009-04-15 03:11:30 +00001713 /* Set maximum receive buffer size. */
1714 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Sascha Hauerf44d6302009-04-15 03:11:30 +00001716 /* Set receive and transmit descriptor base. */
1717 writel(fep->bd_dma, fep->hwp + FEC_R_DES_START);
Sascha Hauer2e285322009-04-15 01:32:16 +00001718 writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE,
Sascha Hauerf44d6302009-04-15 03:11:30 +00001719 fep->hwp + FEC_X_DES_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
1722 fep->cur_rx = fep->rx_bd_base;
1723
Sascha Hauerf44d6302009-04-15 03:11:30 +00001724 /* Reset SKB transmit buffers. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 fep->skb_cur = fep->skb_dirty = 0;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001726 for (i = 0; i <= TX_RING_MOD_MASK; i++) {
1727 if (fep->tx_skbuff[i]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 dev_kfree_skb_any(fep->tx_skbuff[i]);
1729 fep->tx_skbuff[i] = NULL;
1730 }
1731 }
1732
Sascha Hauerf44d6302009-04-15 03:11:30 +00001733 /* Initialize the receive buffer descriptors. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 bdp = fep->rx_bd_base;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001735 for (i = 0; i < RX_RING_SIZE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Sascha Hauerf44d6302009-04-15 03:11:30 +00001737 /* Initialize the BD for every fragment in the page. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 bdp->cbd_sc = BD_ENET_RX_EMPTY;
1739 bdp++;
1740 }
1741
Sascha Hauer22f6b862009-04-15 01:32:18 +00001742 /* Set the last buffer to wrap */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 bdp--;
1744 bdp->cbd_sc |= BD_SC_WRAP;
1745
Sascha Hauer22f6b862009-04-15 01:32:18 +00001746 /* ...and the same for transmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 bdp = fep->tx_bd_base;
Sascha Hauer22f6b862009-04-15 01:32:18 +00001748 for (i = 0; i < TX_RING_SIZE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Sascha Hauerf44d6302009-04-15 03:11:30 +00001750 /* Initialize the BD for every fragment in the page. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 bdp->cbd_sc = 0;
1752 bdp->cbd_bufaddr = 0;
1753 bdp++;
1754 }
1755
Sascha Hauer22f6b862009-04-15 01:32:18 +00001756 /* Set the last buffer to wrap */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 bdp--;
1758 bdp->cbd_sc |= BD_SC_WRAP;
1759
Sascha Hauer22f6b862009-04-15 01:32:18 +00001760 /* Enable MII mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (duplex) {
Sascha Hauerf44d6302009-04-15 03:11:30 +00001762 /* MII enable / FD enable */
1763 writel(OPT_FRAME_SIZE | 0x04, fep->hwp + FEC_R_CNTRL);
1764 writel(0x04, fep->hwp + FEC_X_CNTRL);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10001765 } else {
Sascha Hauerf44d6302009-04-15 03:11:30 +00001766 /* MII enable / No Rcv on Xmit */
1767 writel(OPT_FRAME_SIZE | 0x06, fep->hwp + FEC_R_CNTRL);
1768 writel(0x0, fep->hwp + FEC_X_CNTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 }
1770 fep->full_duplex = duplex;
1771
Sascha Hauer22f6b862009-04-15 01:32:18 +00001772 /* Set MII speed */
Sascha Hauerf44d6302009-04-15 03:11:30 +00001773 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Sascha Hauer22f6b862009-04-15 01:32:18 +00001775 /* And last, enable the transmit and receive processing */
Sascha Hauerf44d6302009-04-15 03:11:30 +00001776 writel(2, fep->hwp + FEC_ECNTRL);
1777 writel(0, fep->hwp + FEC_R_DES_ACTIVE);
Matt Waddel6b265292006-06-27 13:10:56 +10001778
Sascha Hauer22f6b862009-04-15 01:32:18 +00001779 /* Enable interrupts we wish to service */
Sascha Hauerf44d6302009-04-15 03:11:30 +00001780 writel(FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII,
1781 fep->hwp + FEC_IMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782}
1783
1784static void
1785fec_stop(struct net_device *dev)
1786{
Sascha Hauerf44d6302009-04-15 03:11:30 +00001787 struct fec_enet_private *fep = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Sascha Hauer22f6b862009-04-15 01:32:18 +00001789 /* We cannot expect a graceful transmit stop without link !!! */
Sascha Hauerf44d6302009-04-15 03:11:30 +00001790 if (fep->link) {
1791 writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
Philippe De Muyter677177c2006-06-27 13:05:33 +10001792 udelay(10);
Sascha Hauerf44d6302009-04-15 03:11:30 +00001793 if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
Philippe De Muyter677177c2006-06-27 13:05:33 +10001794 printk("fec_stop : Graceful transmit stop did not complete !\n");
Sascha Hauerf44d6302009-04-15 03:11:30 +00001795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Sascha Hauerf44d6302009-04-15 03:11:30 +00001797 /* Whack a reset. We should wait for this. */
1798 writel(1, fep->hwp + FEC_ECNTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 udelay(10);
1800
Sascha Hauerf44d6302009-04-15 03:11:30 +00001801 /* Clear outstanding MII command interrupts. */
1802 writel(FEC_ENET_MII, fep->hwp + FEC_IEVENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Sascha Hauerf44d6302009-04-15 03:11:30 +00001804 writel(FEC_ENET_MII, fep->hwp + FEC_IMASK);
1805 writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
Sascha Haueread73182009-01-28 23:03:11 +00001808static int __devinit
1809fec_probe(struct platform_device *pdev)
1810{
1811 struct fec_enet_private *fep;
1812 struct net_device *ndev;
1813 int i, irq, ret = 0;
1814 struct resource *r;
1815
1816 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1817 if (!r)
1818 return -ENXIO;
1819
1820 r = request_mem_region(r->start, resource_size(r), pdev->name);
1821 if (!r)
1822 return -EBUSY;
1823
1824 /* Init network device */
1825 ndev = alloc_etherdev(sizeof(struct fec_enet_private));
1826 if (!ndev)
1827 return -ENOMEM;
1828
1829 SET_NETDEV_DEV(ndev, &pdev->dev);
1830
1831 /* setup board info structure */
1832 fep = netdev_priv(ndev);
1833 memset(fep, 0, sizeof(*fep));
1834
1835 ndev->base_addr = (unsigned long)ioremap(r->start, resource_size(r));
1836
1837 if (!ndev->base_addr) {
1838 ret = -ENOMEM;
1839 goto failed_ioremap;
1840 }
1841
1842 platform_set_drvdata(pdev, ndev);
1843
1844 /* This device has up to three irqs on some platforms */
1845 for (i = 0; i < 3; i++) {
1846 irq = platform_get_irq(pdev, i);
1847 if (i && irq < 0)
1848 break;
1849 ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
1850 if (ret) {
1851 while (i >= 0) {
1852 irq = platform_get_irq(pdev, i);
1853 free_irq(irq, ndev);
1854 i--;
1855 }
1856 goto failed_irq;
1857 }
1858 }
1859
1860 fep->clk = clk_get(&pdev->dev, "fec_clk");
1861 if (IS_ERR(fep->clk)) {
1862 ret = PTR_ERR(fep->clk);
1863 goto failed_clk;
1864 }
1865 clk_enable(fep->clk);
1866
1867 ret = fec_enet_init(ndev, 0);
1868 if (ret)
1869 goto failed_init;
1870
1871 ret = register_netdev(ndev);
1872 if (ret)
1873 goto failed_register;
1874
1875 return 0;
1876
1877failed_register:
1878failed_init:
1879 clk_disable(fep->clk);
1880 clk_put(fep->clk);
1881failed_clk:
1882 for (i = 0; i < 3; i++) {
1883 irq = platform_get_irq(pdev, i);
1884 if (irq > 0)
1885 free_irq(irq, ndev);
1886 }
1887failed_irq:
1888 iounmap((void __iomem *)ndev->base_addr);
1889failed_ioremap:
1890 free_netdev(ndev);
1891
1892 return ret;
1893}
1894
1895static int __devexit
1896fec_drv_remove(struct platform_device *pdev)
1897{
1898 struct net_device *ndev = platform_get_drvdata(pdev);
1899 struct fec_enet_private *fep = netdev_priv(ndev);
1900
1901 platform_set_drvdata(pdev, NULL);
1902
1903 fec_stop(ndev);
1904 clk_disable(fep->clk);
1905 clk_put(fep->clk);
1906 iounmap((void __iomem *)ndev->base_addr);
1907 unregister_netdev(ndev);
1908 free_netdev(ndev);
1909 return 0;
1910}
1911
1912static int
1913fec_suspend(struct platform_device *dev, pm_message_t state)
1914{
1915 struct net_device *ndev = platform_get_drvdata(dev);
1916 struct fec_enet_private *fep;
1917
1918 if (ndev) {
1919 fep = netdev_priv(ndev);
1920 if (netif_running(ndev)) {
1921 netif_device_detach(ndev);
1922 fec_stop(ndev);
1923 }
1924 }
1925 return 0;
1926}
1927
1928static int
1929fec_resume(struct platform_device *dev)
1930{
1931 struct net_device *ndev = platform_get_drvdata(dev);
1932
1933 if (ndev) {
1934 if (netif_running(ndev)) {
1935 fec_enet_init(ndev, 0);
1936 netif_device_attach(ndev);
1937 }
1938 }
1939 return 0;
1940}
1941
1942static struct platform_driver fec_driver = {
1943 .driver = {
1944 .name = "fec",
1945 .owner = THIS_MODULE,
1946 },
1947 .probe = fec_probe,
1948 .remove = __devexit_p(fec_drv_remove),
1949 .suspend = fec_suspend,
1950 .resume = fec_resume,
1951};
1952
1953static int __init
1954fec_enet_module_init(void)
1955{
1956 printk(KERN_INFO "FEC Ethernet Driver\n");
1957
1958 return platform_driver_register(&fec_driver);
1959}
1960
1961static void __exit
1962fec_enet_cleanup(void)
1963{
1964 platform_driver_unregister(&fec_driver);
1965}
1966
1967module_exit(fec_enet_cleanup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968module_init(fec_enet_module_init);
1969
1970MODULE_LICENSE("GPL");