blob: 5f9c2c1a9d404bc58d3c678f2640ed9d0f021eb2 [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 *
5 * This version of the driver is specific to the FADS implementation,
6 * since the board contains control registers external to the processor
7 * for the control of the LevelOne LXT970 transceiver. The MPC860T manual
8 * describes connections using the internal parallel port I/O, which
9 * is basically all of Port D.
10 *
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100011 * Right now, I am very wasteful with the buffers. I allocate memory
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * pages and then divide them into 2K frame buffers. This way I know I
13 * have buffers large enough to hold one frame within one buffer descriptor.
14 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
15 * will be much more memory efficient and will easily handle lots of
16 * small packets.
17 *
18 * Much better multiple PHY support by Magnus Damm.
19 * Copyright (c) 2000 Ericsson Radio Systems AB.
20 *
Greg Ungerer562d2f82005-11-07 14:09:50 +100021 * Support for FEC controller of ColdFire processors.
22 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100023 *
24 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
Philippe De Muyter677177c2006-06-27 13:05:33 +100025 * Copyright (c) 2004-2006 Macq Electronique SA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/string.h>
31#include <linux/ptrace.h>
32#include <linux/errno.h>
33#include <linux/ioport.h>
34#include <linux/slab.h>
35#include <linux/interrupt.h>
36#include <linux/pci.h>
37#include <linux/init.h>
38#include <linux/delay.h>
39#include <linux/netdevice.h>
40#include <linux/etherdevice.h>
41#include <linux/skbuff.h>
42#include <linux/spinlock.h>
43#include <linux/workqueue.h>
44#include <linux/bitops.h>
45
46#include <asm/irq.h>
47#include <asm/uaccess.h>
48#include <asm/io.h>
49#include <asm/pgtable.h>
Greg Ungerer080853a2007-07-30 16:28:46 +100050#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100052#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
Greg Ungerer562d2f82005-11-07 14:09:50 +100053 defined(CONFIG_M5272) || defined(CONFIG_M528x) || \
Matt Waddel6b265292006-06-27 13:10:56 +100054 defined(CONFIG_M520x) || defined(CONFIG_M532x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/coldfire.h>
56#include <asm/mcfsim.h>
57#include "fec.h"
58#else
59#include <asm/8xx_immap.h>
60#include <asm/mpc8xx.h>
61#include "commproc.h"
62#endif
63
64#if defined(CONFIG_FEC2)
65#define FEC_MAX_PORTS 2
66#else
67#define FEC_MAX_PORTS 1
68#endif
69
Sebastian Siewiorc1d96152008-05-01 14:04:02 +100070#if defined(CONFIG_FADS) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_M5272)
71#define HAVE_mii_link_interrupt
72#endif
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/*
75 * Define the fixed address of the FEC hardware.
76 */
77static unsigned int fec_hw[] = {
78#if defined(CONFIG_M5272)
79 (MCF_MBAR + 0x840),
80#elif defined(CONFIG_M527x)
81 (MCF_MBAR + 0x1000),
82 (MCF_MBAR + 0x1800),
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100083#elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 (MCF_MBAR + 0x1000),
Greg Ungerer562d2f82005-11-07 14:09:50 +100085#elif defined(CONFIG_M520x)
86 (MCF_MBAR+0x30000),
Matt Waddel6b265292006-06-27 13:10:56 +100087#elif defined(CONFIG_M532x)
88 (MCF_MBAR+0xfc030000),
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#else
90 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
91#endif
92};
93
94static unsigned char fec_mac_default[] = {
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96};
97
98/*
99 * Some hardware gets it MAC address out of local flash memory.
100 * if this is non-zero then assume it is the address to get MAC from.
101 */
102#if defined(CONFIG_NETtel)
103#define FEC_FLASHMAC 0xf0006006
104#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
105#define FEC_FLASHMAC 0xf0006000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#elif defined(CONFIG_CANCam)
107#define FEC_FLASHMAC 0xf0020000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000108#elif defined (CONFIG_M5272C3)
109#define FEC_FLASHMAC (0xffe04000 + 4)
110#elif defined(CONFIG_MOD5272)
111#define FEC_FLASHMAC 0xffc0406b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#else
113#define FEC_FLASHMAC 0
114#endif
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* Forward declarations of some structures to support different PHYs
117*/
118
119typedef struct {
120 uint mii_data;
121 void (*funct)(uint mii_reg, struct net_device *dev);
122} phy_cmd_t;
123
124typedef struct {
125 uint id;
126 char *name;
127
128 const phy_cmd_t *config;
129 const phy_cmd_t *startup;
130 const phy_cmd_t *ack_int;
131 const phy_cmd_t *shutdown;
132} phy_info_t;
133
134/* The number of Tx and Rx buffers. These are allocated from the page
135 * pool. The code may assume these are power of two, so it it best
136 * to keep them that size.
137 * We don't need to allocate pages for the transmitter. We just use
138 * the skbuffer directly.
139 */
140#define FEC_ENET_RX_PAGES 8
141#define FEC_ENET_RX_FRSIZE 2048
142#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
143#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
144#define FEC_ENET_TX_FRSIZE 2048
145#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
146#define TX_RING_SIZE 16 /* Must be power of two */
147#define TX_RING_MOD_MASK 15 /* for this to work */
148
Greg Ungerer562d2f82005-11-07 14:09:50 +1000149#if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
Matt Waddel6b265292006-06-27 13:10:56 +1000150#error "FEC: descriptor ring size constants too large"
Greg Ungerer562d2f82005-11-07 14:09:50 +1000151#endif
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/* Interrupt events/masks.
154*/
155#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
156#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
157#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
158#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
159#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
160#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
161#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
162#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
163#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
164#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
165
166/* The FEC stores dest/src/type, data, and checksum for receive packets.
167 */
168#define PKT_MAXBUF_SIZE 1518
169#define PKT_MINBUF_SIZE 64
170#define PKT_MAXBLR_SIZE 1520
171
172
173/*
Matt Waddel6b265292006-06-27 13:10:56 +1000174 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 * size bits. Other FEC hardware does not, so we need to take that into
176 * account when setting it.
177 */
Greg Ungerer562d2f82005-11-07 14:09:50 +1000178#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
Matt Waddel6b265292006-06-27 13:10:56 +1000179 defined(CONFIG_M520x) || defined(CONFIG_M532x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
181#else
182#define OPT_FRAME_SIZE 0
183#endif
184
185/* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
186 * tx_bd_base always point to the base of the buffer descriptors. The
187 * cur_rx and cur_tx point to the currently available buffer.
188 * The dirty_tx tracks the current buffer that is being sent by the
189 * controller. The cur_tx and dirty_tx are equal under both completely
190 * empty and completely full conditions. The empty/ready indicator in
191 * the buffer descriptor determines the actual condition.
192 */
193struct fec_enet_private {
194 /* Hardware registers of the FEC device */
195 volatile fec_t *hwp;
196
Greg Ungerercb84d6e2007-07-30 16:29:09 +1000197 struct net_device *netdev;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
200 unsigned char *tx_bounce[TX_RING_SIZE];
201 struct sk_buff* tx_skbuff[TX_RING_SIZE];
202 ushort skb_cur;
203 ushort skb_dirty;
204
205 /* CPM dual port RAM relative addresses.
206 */
207 cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
208 cbd_t *tx_bd_base;
209 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
210 cbd_t *dirty_tx; /* The ring entries to be free()ed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 uint tx_full;
212 spinlock_t lock;
213
214 uint phy_id;
215 uint phy_id_done;
216 uint phy_status;
217 uint phy_speed;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000218 phy_info_t const *phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 struct work_struct phy_task;
220
221 uint sequence_done;
222 uint mii_phy_task_queued;
223
224 uint phy_addr;
225
226 int index;
227 int opened;
228 int link;
229 int old_link;
230 int full_duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233static int fec_enet_open(struct net_device *dev);
234static int fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
235static void fec_enet_mii(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100236static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static void fec_enet_tx(struct net_device *dev);
238static void fec_enet_rx(struct net_device *dev);
239static int fec_enet_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static void set_multicast_list(struct net_device *dev);
241static void fec_restart(struct net_device *dev, int duplex);
242static void fec_stop(struct net_device *dev);
243static void fec_set_mac_address(struct net_device *dev);
244
245
246/* MII processing. We keep this as simple as possible. Requests are
247 * placed on the list (if there is room). When the request is finished
248 * by the MII, an optional function may be called.
249 */
250typedef struct mii_list {
251 uint mii_regval;
252 void (*mii_func)(uint val, struct net_device *dev);
253 struct mii_list *mii_next;
254} mii_list_t;
255
256#define NMII 20
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000257static mii_list_t mii_cmds[NMII];
258static mii_list_t *mii_free;
259static mii_list_t *mii_head;
260static mii_list_t *mii_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400262static int mii_queue(struct net_device *dev, int request,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 void (*func)(uint, struct net_device *));
264
265/* Make MII read/write commands for the FEC.
266*/
267#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
268#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
269 (VAL & 0xffff))
270#define mk_mii_end 0
271
272/* Transmitter timeout.
273*/
274#define TX_TIMEOUT (2*HZ)
275
276/* Register definitions for the PHY.
277*/
278
279#define MII_REG_CR 0 /* Control Register */
280#define MII_REG_SR 1 /* Status Register */
281#define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
282#define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400283#define MII_REG_ANAR 4 /* A-N Advertisement Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
285#define MII_REG_ANER 6 /* A-N Expansion Register */
286#define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
287#define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
288
289/* values for phy_status */
290
291#define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
292#define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
293#define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
294#define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400295#define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400297#define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299#define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
300#define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
301#define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
302#define PHY_STAT_SPMASK 0xf000 /* mask for speed */
303#define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400304#define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400306#define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308
309static int
310fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
311{
312 struct fec_enet_private *fep;
313 volatile fec_t *fecp;
314 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000315 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 fep = netdev_priv(dev);
318 fecp = (volatile fec_t*)dev->base_addr;
319
320 if (!fep->link) {
321 /* Link is down or autonegotiation is in progress. */
322 return 1;
323 }
324
325 /* Fill in a Tx ring entry */
326 bdp = fep->cur_tx;
327
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000328 status = bdp->cbd_sc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#ifndef final_version
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000330 if (status & BD_ENET_TX_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 /* Ooops. All transmit buffers are full. Bail out.
332 * This should not happen, since dev->tbusy should be set.
333 */
334 printk("%s: tx queue full!.\n", dev->name);
335 return 1;
336 }
337#endif
338
339 /* Clear all of the status flags.
340 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000341 status &= ~BD_ENET_TX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* Set buffer length and buffer pointer.
344 */
345 bdp->cbd_bufaddr = __pa(skb->data);
346 bdp->cbd_datlen = skb->len;
347
348 /*
349 * On some FEC implementations data must be aligned on
350 * 4-byte boundaries. Use bounce buffers to copy data
351 * and get it aligned. Ugh.
352 */
353 if (bdp->cbd_bufaddr & 0x3) {
354 unsigned int index;
355 index = bdp - fep->tx_bd_base;
356 memcpy(fep->tx_bounce[index], (void *) bdp->cbd_bufaddr, bdp->cbd_datlen);
357 bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
358 }
359
360 /* Save skb pointer.
361 */
362 fep->tx_skbuff[fep->skb_cur] = skb;
363
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700364 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* Push the data cache so the CPM does not get stale memory
368 * data.
369 */
370 flush_dcache_range((unsigned long)skb->data,
371 (unsigned long)skb->data + skb->len);
372
373 spin_lock_irq(&fep->lock);
374
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000375 /* Send it on its way. Tell FEC it's ready, interrupt when done,
376 * it's the last BD of the frame, and to put the CRC on the end.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 */
378
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000379 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000381 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 dev->trans_start = jiffies;
384
385 /* Trigger transmission start */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000386 fecp->fec_x_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 /* If this was the last BD in the ring, start at the beginning again.
389 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000390 if (status & BD_ENET_TX_WRAP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 bdp = fep->tx_bd_base;
392 } else {
393 bdp++;
394 }
395
396 if (bdp == fep->dirty_tx) {
397 fep->tx_full = 1;
398 netif_stop_queue(dev);
399 }
400
401 fep->cur_tx = (cbd_t *)bdp;
402
403 spin_unlock_irq(&fep->lock);
404
405 return 0;
406}
407
408static void
409fec_timeout(struct net_device *dev)
410{
411 struct fec_enet_private *fep = netdev_priv(dev);
412
413 printk("%s: transmit timed out.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700414 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#ifndef final_version
416 {
417 int i;
418 cbd_t *bdp;
419
420 printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
421 (unsigned long)fep->cur_tx, fep->tx_full ? " (full)" : "",
422 (unsigned long)fep->dirty_tx,
423 (unsigned long)fep->cur_rx);
424
425 bdp = fep->tx_bd_base;
426 printk(" tx: %u buffers\n", TX_RING_SIZE);
427 for (i = 0 ; i < TX_RING_SIZE; i++) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400428 printk(" %08x: %04x %04x %08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 (uint) bdp,
430 bdp->cbd_sc,
431 bdp->cbd_datlen,
432 (int) bdp->cbd_bufaddr);
433 bdp++;
434 }
435
436 bdp = fep->rx_bd_base;
437 printk(" rx: %lu buffers\n", (unsigned long) RX_RING_SIZE);
438 for (i = 0 ; i < RX_RING_SIZE; i++) {
439 printk(" %08x: %04x %04x %08x\n",
440 (uint) bdp,
441 bdp->cbd_sc,
442 bdp->cbd_datlen,
443 (int) bdp->cbd_bufaddr);
444 bdp++;
445 }
446 }
447#endif
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000448 fec_restart(dev, fep->full_duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 netif_wake_queue(dev);
450}
451
452/* The interrupt handler.
453 * This is called from the MPC core interrupt.
454 */
455static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100456fec_enet_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
458 struct net_device *dev = dev_id;
459 volatile fec_t *fecp;
460 uint int_events;
461 int handled = 0;
462
463 fecp = (volatile fec_t*)dev->base_addr;
464
465 /* Get the interrupt events that caused us to be here.
466 */
467 while ((int_events = fecp->fec_ievent) != 0) {
468 fecp->fec_ievent = int_events;
469
470 /* Handle receive event in its own function.
471 */
472 if (int_events & FEC_ENET_RXF) {
473 handled = 1;
474 fec_enet_rx(dev);
475 }
476
477 /* Transmit OK, or non-fatal error. Update the buffer
478 descriptors. FEC handles all errors, we just discover
479 them as part of the transmit process.
480 */
481 if (int_events & FEC_ENET_TXF) {
482 handled = 1;
483 fec_enet_tx(dev);
484 }
485
486 if (int_events & FEC_ENET_MII) {
487 handled = 1;
488 fec_enet_mii(dev);
489 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492 return IRQ_RETVAL(handled);
493}
494
495
496static void
497fec_enet_tx(struct net_device *dev)
498{
499 struct fec_enet_private *fep;
500 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000501 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 struct sk_buff *skb;
503
504 fep = netdev_priv(dev);
505 spin_lock(&fep->lock);
506 bdp = fep->dirty_tx;
507
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000508 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (bdp == fep->cur_tx && fep->tx_full == 0) break;
510
511 skb = fep->tx_skbuff[fep->skb_dirty];
512 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000513 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 BD_ENET_TX_RL | BD_ENET_TX_UN |
515 BD_ENET_TX_CSL)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700516 dev->stats.tx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000517 if (status & BD_ENET_TX_HB) /* No heartbeat */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700518 dev->stats.tx_heartbeat_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000519 if (status & BD_ENET_TX_LC) /* Late collision */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700520 dev->stats.tx_window_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000521 if (status & BD_ENET_TX_RL) /* Retrans limit */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700522 dev->stats.tx_aborted_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000523 if (status & BD_ENET_TX_UN) /* Underrun */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700524 dev->stats.tx_fifo_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000525 if (status & BD_ENET_TX_CSL) /* Carrier lost */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700526 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700528 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530
531#ifndef final_version
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000532 if (status & BD_ENET_TX_READY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 printk("HEY! Enet xmit interrupt and TX_READY.\n");
534#endif
535 /* Deferred means some collisions occurred during transmit,
536 * but we eventually sent the packet OK.
537 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000538 if (status & BD_ENET_TX_DEF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700539 dev->stats.collisions++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 /* Free the sk buffer associated with this last transmit.
542 */
543 dev_kfree_skb_any(skb);
544 fep->tx_skbuff[fep->skb_dirty] = NULL;
545 fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 /* Update pointer to next buffer descriptor to be transmitted.
548 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000549 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 bdp = fep->tx_bd_base;
551 else
552 bdp++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 /* Since we have freed up a buffer, the ring is no longer
555 * full.
556 */
557 if (fep->tx_full) {
558 fep->tx_full = 0;
559 if (netif_queue_stopped(dev))
560 netif_wake_queue(dev);
561 }
562 }
563 fep->dirty_tx = (cbd_t *)bdp;
564 spin_unlock(&fep->lock);
565}
566
567
568/* During a receive, the cur_rx points to the current incoming buffer.
569 * When we update through the ring, if the next incoming buffer has
570 * not been given to the system, we just set the empty indicator,
571 * effectively tossing the packet.
572 */
573static void
574fec_enet_rx(struct net_device *dev)
575{
576 struct fec_enet_private *fep;
577 volatile fec_t *fecp;
578 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000579 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 struct sk_buff *skb;
581 ushort pkt_len;
582 __u8 *data;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400583
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000584#ifdef CONFIG_M532x
585 flush_cache_all();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400586#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 fep = netdev_priv(dev);
589 fecp = (volatile fec_t*)dev->base_addr;
590
591 /* First, grab all of the stats for the incoming packet.
592 * These get messed up if we get called due to a busy condition.
593 */
594 bdp = fep->cur_rx;
595
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000596while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598#ifndef final_version
599 /* Since we have allocated space to hold a complete frame,
600 * the last indicator should be set.
601 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000602 if ((status & BD_ENET_RX_LAST) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 printk("FEC ENET: rcv is not +last\n");
604#endif
605
606 if (!fep->opened)
607 goto rx_processing_done;
608
609 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000610 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700612 dev->stats.rx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000613 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /* Frame too long or too short. */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700615 dev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000617 if (status & BD_ENET_RX_NO) /* Frame alignment */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700618 dev->stats.rx_frame_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000619 if (status & BD_ENET_RX_CR) /* CRC Error */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700620 dev->stats.rx_crc_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000621 if (status & BD_ENET_RX_OV) /* FIFO overrun */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700622 dev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624
625 /* Report late collisions as a frame error.
626 * On this error, the BD is closed, but we don't know what we
627 * have in the buffer. So, just drop this frame on the floor.
628 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000629 if (status & BD_ENET_RX_CL) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700630 dev->stats.rx_errors++;
631 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 goto rx_processing_done;
633 }
634
635 /* Process the incoming frame.
636 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700637 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 pkt_len = bdp->cbd_datlen;
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700639 dev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 data = (__u8*)__va(bdp->cbd_bufaddr);
641
642 /* This does 16 byte alignment, exactly what we need.
643 * The packet length includes FCS, but we don't want to
644 * include that when passing upstream as it messes up
645 * bridging applications.
646 */
647 skb = dev_alloc_skb(pkt_len-4);
648
649 if (skb == NULL) {
650 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700651 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 skb_put(skb,pkt_len-4); /* Make room */
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700654 skb_copy_to_linear_data(skb, data, pkt_len-4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 skb->protocol=eth_type_trans(skb,dev);
656 netif_rx(skb);
657 }
658 rx_processing_done:
659
660 /* Clear the status flags for this buffer.
661 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000662 status &= ~BD_ENET_RX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 /* Mark the buffer empty.
665 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000666 status |= BD_ENET_RX_EMPTY;
667 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 /* Update BD pointer to next entry.
670 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000671 if (status & BD_ENET_RX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 bdp = fep->rx_bd_base;
673 else
674 bdp++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#if 1
677 /* Doing this here will keep the FEC running while we process
678 * incoming frames. On a heavily loaded network, we should be
679 * able to keep up at the expense of system resources.
680 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000681 fecp->fec_r_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682#endif
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000683 } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 fep->cur_rx = (cbd_t *)bdp;
685
686#if 0
687 /* Doing this here will allow us to process all frames in the
688 * ring before the FEC is allowed to put more there. On a heavily
689 * loaded network, some frames may be lost. Unfortunately, this
690 * increases the interrupt overhead since we can potentially work
691 * our way back to the interrupt return only to come right back
692 * here.
693 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000694 fecp->fec_r_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#endif
696}
697
698
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000699/* called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700static void
701fec_enet_mii(struct net_device *dev)
702{
703 struct fec_enet_private *fep;
704 volatile fec_t *ep;
705 mii_list_t *mip;
706 uint mii_reg;
707
708 fep = netdev_priv(dev);
709 ep = fep->hwp;
710 mii_reg = ep->fec_mii_data;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000711
712 spin_lock(&fep->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if ((mip = mii_head) == NULL) {
715 printk("MII and no head!\n");
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000716 goto unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
719 if (mip->mii_func != NULL)
720 (*(mip->mii_func))(mii_reg, dev);
721
722 mii_head = mip->mii_next;
723 mip->mii_next = mii_free;
724 mii_free = mip;
725
726 if ((mip = mii_head) != NULL)
727 ep->fec_mii_data = mip->mii_regval;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000728
729unlock:
730 spin_unlock(&fep->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
732
733static int
734mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
735{
736 struct fec_enet_private *fep;
737 unsigned long flags;
738 mii_list_t *mip;
739 int retval;
740
741 /* Add PHY address to register command.
742 */
743 fep = netdev_priv(dev);
744 regval |= fep->phy_addr << 23;
745
746 retval = 0;
747
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000748 spin_lock_irqsave(&fep->lock,flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 if ((mip = mii_free) != NULL) {
751 mii_free = mip->mii_next;
752 mip->mii_regval = regval;
753 mip->mii_func = func;
754 mip->mii_next = NULL;
755 if (mii_head) {
756 mii_tail->mii_next = mip;
757 mii_tail = mip;
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000758 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 mii_head = mii_tail = mip;
760 fep->hwp->fec_mii_data = regval;
761 }
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000762 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 retval = 1;
764 }
765
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000766 spin_unlock_irqrestore(&fep->lock,flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 return(retval);
769}
770
771static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
772{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if(!c)
774 return;
775
Philippe De Muyterbe6cb662007-10-23 14:37:54 +1000776 for (; c->mii_data != mk_mii_end; c++)
777 mii_queue(dev, c->mii_data, c->funct);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
780static void mii_parse_sr(uint mii_reg, struct net_device *dev)
781{
782 struct fec_enet_private *fep = netdev_priv(dev);
783 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000784 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000786 status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 if (mii_reg & 0x0004)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000789 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (mii_reg & 0x0010)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000791 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000793 status |= PHY_STAT_ANC;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000794 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
797static void mii_parse_cr(uint mii_reg, struct net_device *dev)
798{
799 struct fec_enet_private *fep = netdev_priv(dev);
800 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000801 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000803 status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000806 status |= PHY_CONF_ANE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (mii_reg & 0x4000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000808 status |= PHY_CONF_LOOP;
809 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
812static void mii_parse_anar(uint mii_reg, struct net_device *dev)
813{
814 struct fec_enet_private *fep = netdev_priv(dev);
815 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000816 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000818 status = *s & ~(PHY_CONF_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000821 status |= PHY_CONF_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (mii_reg & 0x0040)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000823 status |= PHY_CONF_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000825 status |= PHY_CONF_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (mii_reg & 0x00100)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000827 status |= PHY_CONF_100FDX;
828 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
831/* ------------------------------------------------------------------------- */
832/* The Level one LXT970 is used by many boards */
833
834#define MII_LXT970_MIRROR 16 /* Mirror register */
835#define MII_LXT970_IER 17 /* Interrupt Enable Register */
836#define MII_LXT970_ISR 18 /* Interrupt Status Register */
837#define MII_LXT970_CONFIG 19 /* Configuration Register */
838#define MII_LXT970_CSR 20 /* Chip Status Register */
839
840static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
841{
842 struct fec_enet_private *fep = netdev_priv(dev);
843 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000844 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000846 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (mii_reg & 0x0800) {
848 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000849 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000851 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 } else {
853 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000854 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000856 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000858 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000861static phy_cmd_t const phy_cmd_lxt970_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 { mk_mii_read(MII_REG_CR), mii_parse_cr },
863 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
864 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000865 };
866static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
868 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
869 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000870 };
871static phy_cmd_t const phy_cmd_lxt970_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /* read SR and ISR to acknowledge */
873 { mk_mii_read(MII_REG_SR), mii_parse_sr },
874 { mk_mii_read(MII_LXT970_ISR), NULL },
875
876 /* find out the current status */
877 { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
878 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000879 };
880static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
882 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000883 };
884static phy_info_t const phy_info_lxt970 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400885 .id = 0x07810000,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000886 .name = "LXT970",
887 .config = phy_cmd_lxt970_config,
888 .startup = phy_cmd_lxt970_startup,
889 .ack_int = phy_cmd_lxt970_ack_int,
890 .shutdown = phy_cmd_lxt970_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893/* ------------------------------------------------------------------------- */
894/* The Level one LXT971 is used on some of my custom boards */
895
896/* register definitions for the 971 */
897
898#define MII_LXT971_PCR 16 /* Port Control Register */
899#define MII_LXT971_SR2 17 /* Status Register 2 */
900#define MII_LXT971_IER 18 /* Interrupt Enable Register */
901#define MII_LXT971_ISR 19 /* Interrupt Status Register */
902#define MII_LXT971_LCR 20 /* LED Control Register */
903#define MII_LXT971_TCR 30 /* Transmit Control Register */
904
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400905/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 * I had some nice ideas of running the MDIO faster...
907 * The 971 should support 8MHz and I tried it, but things acted really
908 * weird, so 2.5 MHz ought to be enough for anyone...
909 */
910
911static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
912{
913 struct fec_enet_private *fep = netdev_priv(dev);
914 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000915 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000917 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 if (mii_reg & 0x0400) {
920 fep->link = 1;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000921 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 } else {
923 fep->link = 0;
924 }
925 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000926 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 if (mii_reg & 0x4000) {
928 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000929 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000931 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 } else {
933 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000934 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000936 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
938 if (mii_reg & 0x0008)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000939 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000941 *s = status;
942}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400943
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000944static phy_cmd_t const phy_cmd_lxt971_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400945 /* limit to 10MBit because my prototype board
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 * doesn't work with 100. */
947 { mk_mii_read(MII_REG_CR), mii_parse_cr },
948 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
949 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
950 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000951 };
952static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
954 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
955 { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */
956 /* Somehow does the 971 tell me that the link is down
957 * the first read after power-up.
958 * read here to get a valid value in ack_int */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400959 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000961 };
962static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
963 /* acknowledge the int before reading status ! */
964 { mk_mii_read(MII_LXT971_ISR), NULL },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 /* find out the current status */
966 { mk_mii_read(MII_REG_SR), mii_parse_sr },
967 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000969 };
970static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
972 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000973 };
974static phy_info_t const phy_info_lxt971 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400975 .id = 0x0001378e,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000976 .name = "LXT971",
977 .config = phy_cmd_lxt971_config,
978 .startup = phy_cmd_lxt971_startup,
979 .ack_int = phy_cmd_lxt971_ack_int,
980 .shutdown = phy_cmd_lxt971_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981};
982
983/* ------------------------------------------------------------------------- */
984/* The Quality Semiconductor QS6612 is used on the RPX CLLF */
985
986/* register definitions */
987
988#define MII_QS6612_MCR 17 /* Mode Control Register */
989#define MII_QS6612_FTR 27 /* Factory Test Register */
990#define MII_QS6612_MCO 28 /* Misc. Control Register */
991#define MII_QS6612_ISR 29 /* Interrupt Source Register */
992#define MII_QS6612_IMR 30 /* Interrupt Mask Register */
993#define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
994
995static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
996{
997 struct fec_enet_private *fep = netdev_priv(dev);
998 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000999 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001001 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 switch((mii_reg >> 2) & 7) {
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001004 case 1: status |= PHY_STAT_10HDX; break;
1005 case 2: status |= PHY_STAT_100HDX; break;
1006 case 5: status |= PHY_STAT_10FDX; break;
1007 case 6: status |= PHY_STAT_100FDX; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001010 *s = status;
1011}
1012
1013static phy_cmd_t const phy_cmd_qs6612_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001014 /* The PHY powers up isolated on the RPX,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 * so send a command to allow operation.
1016 */
1017 { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
1018
1019 /* parse cr and anar to get some info */
1020 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1021 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1022 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001023 };
1024static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
1026 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1027 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001028 };
1029static phy_cmd_t const phy_cmd_qs6612_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 /* we need to read ISR, SR and ANER to acknowledge */
1031 { mk_mii_read(MII_QS6612_ISR), NULL },
1032 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1033 { mk_mii_read(MII_REG_ANER), NULL },
1034
1035 /* read pcr to get info */
1036 { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
1037 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001038 };
1039static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
1041 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001042 };
1043static phy_info_t const phy_info_qs6612 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001044 .id = 0x00181440,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001045 .name = "QS6612",
1046 .config = phy_cmd_qs6612_config,
1047 .startup = phy_cmd_qs6612_startup,
1048 .ack_int = phy_cmd_qs6612_ack_int,
1049 .shutdown = phy_cmd_qs6612_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050};
1051
1052/* ------------------------------------------------------------------------- */
1053/* AMD AM79C874 phy */
1054
1055/* register definitions for the 874 */
1056
1057#define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
1058#define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
1059#define MII_AM79C874_DR 18 /* Diagnostic Register */
1060#define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
1061#define MII_AM79C874_MCR 21 /* ModeControl Register */
1062#define MII_AM79C874_DC 23 /* Disconnect Counter */
1063#define MII_AM79C874_REC 24 /* Recieve Error Counter */
1064
1065static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev)
1066{
1067 struct fec_enet_private *fep = netdev_priv(dev);
1068 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001069 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001071 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001074 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (mii_reg & 0x0400)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001076 status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001078 status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
1079
1080 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001083static phy_cmd_t const phy_cmd_am79c874_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1085 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1086 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1087 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001088 };
1089static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
1091 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001092 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001094 };
1095static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 /* find out the current status */
1097 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1098 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1099 /* we only need to read ISR to acknowledge */
1100 { mk_mii_read(MII_AM79C874_ICSR), NULL },
1101 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001102 };
1103static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL },
1105 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001106 };
1107static phy_info_t const phy_info_am79c874 = {
1108 .id = 0x00022561,
1109 .name = "AM79C874",
1110 .config = phy_cmd_am79c874_config,
1111 .startup = phy_cmd_am79c874_startup,
1112 .ack_int = phy_cmd_am79c874_ack_int,
1113 .shutdown = phy_cmd_am79c874_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114};
1115
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117/* ------------------------------------------------------------------------- */
1118/* Kendin KS8721BL phy */
1119
1120/* register definitions for the 8721 */
1121
1122#define MII_KS8721BL_RXERCR 21
1123#define MII_KS8721BL_ICSR 22
1124#define MII_KS8721BL_PHYCR 31
1125
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001126static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1128 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1129 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001130 };
1131static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
1133 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001134 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001136 };
1137static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 /* find out the current status */
1139 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1140 /* we only need to read ISR to acknowledge */
1141 { mk_mii_read(MII_KS8721BL_ICSR), NULL },
1142 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001143 };
1144static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL },
1146 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001147 };
1148static phy_info_t const phy_info_ks8721bl = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001149 .id = 0x00022161,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001150 .name = "KS8721BL",
1151 .config = phy_cmd_ks8721bl_config,
1152 .startup = phy_cmd_ks8721bl_startup,
1153 .ack_int = phy_cmd_ks8721bl_ack_int,
1154 .shutdown = phy_cmd_ks8721bl_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155};
1156
1157/* ------------------------------------------------------------------------- */
Greg Ungerer562d2f82005-11-07 14:09:50 +10001158/* register definitions for the DP83848 */
1159
1160#define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
1161
1162static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
1163{
1164 struct fec_enet_private *fep = dev->priv;
1165 volatile uint *s = &(fep->phy_status);
1166
1167 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
1168
1169 /* Link up */
1170 if (mii_reg & 0x0001) {
1171 fep->link = 1;
1172 *s |= PHY_STAT_LINK;
1173 } else
1174 fep->link = 0;
1175 /* Status of link */
1176 if (mii_reg & 0x0010) /* Autonegotioation complete */
1177 *s |= PHY_STAT_ANC;
1178 if (mii_reg & 0x0002) { /* 10MBps? */
1179 if (mii_reg & 0x0004) /* Full Duplex? */
1180 *s |= PHY_STAT_10FDX;
1181 else
1182 *s |= PHY_STAT_10HDX;
1183 } else { /* 100 Mbps? */
1184 if (mii_reg & 0x0004) /* Full Duplex? */
1185 *s |= PHY_STAT_100FDX;
1186 else
1187 *s |= PHY_STAT_100HDX;
1188 }
1189 if (mii_reg & 0x0008)
1190 *s |= PHY_STAT_FAULT;
1191}
1192
1193static phy_info_t phy_info_dp83848= {
1194 0x020005c9,
1195 "DP83848",
1196
1197 (const phy_cmd_t []) { /* config */
1198 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1199 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1200 { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
1201 { mk_mii_end, }
1202 },
1203 (const phy_cmd_t []) { /* startup - enable interrupts */
1204 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1205 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1206 { mk_mii_end, }
1207 },
1208 (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
1209 { mk_mii_end, }
1210 },
1211 (const phy_cmd_t []) { /* shutdown */
1212 { mk_mii_end, }
1213 },
1214};
1215
1216/* ------------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001218static phy_info_t const * const phy_info[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 &phy_info_lxt970,
1220 &phy_info_lxt971,
1221 &phy_info_qs6612,
1222 &phy_info_am79c874,
1223 &phy_info_ks8721bl,
Greg Ungerer562d2f82005-11-07 14:09:50 +10001224 &phy_info_dp83848,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 NULL
1226};
1227
1228/* ------------------------------------------------------------------------- */
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10001229#ifdef HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230#ifdef CONFIG_RPXCLASSIC
1231static void
1232mii_link_interrupt(void *dev_id);
1233#else
1234static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001235mii_link_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236#endif
Matt Waddel6b265292006-06-27 13:10:56 +10001237#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
1239#if defined(CONFIG_M5272)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240/*
1241 * Code specific to Coldfire 5272 setup.
1242 */
1243static void __inline__ fec_request_intrs(struct net_device *dev)
1244{
1245 volatile unsigned long *icrp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001246 static const struct idesc {
1247 char *name;
1248 unsigned short irq;
David Howells7d12e782006-10-05 14:55:46 +01001249 irq_handler_t handler;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001250 } *idp, id[] = {
1251 { "fec(RX)", 86, fec_enet_interrupt },
1252 { "fec(TX)", 87, fec_enet_interrupt },
1253 { "fec(OTHER)", 88, fec_enet_interrupt },
1254 { "fec(MII)", 66, mii_link_interrupt },
1255 { NULL },
1256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258 /* Setup interrupt handlers. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001259 for (idp = id; idp->name; idp++) {
Greg Ungerer0a504772008-03-04 16:52:01 +10001260 if (request_irq(idp->irq, idp->handler, IRQF_DISABLED, idp->name, dev) != 0)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001261 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, idp->irq);
1262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 /* Unmask interrupt at ColdFire 5272 SIM */
1265 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3);
1266 *icrp = 0x00000ddd;
1267 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001268 *icrp = 0x0d000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
1271static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1272{
1273 volatile fec_t *fecp;
1274
1275 fecp = fep->hwp;
1276 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1277 fecp->fec_x_cntrl = 0x00;
1278
1279 /*
1280 * Set MII speed to 2.5 MHz
1281 * See 5272 manual section 11.5.8: MSCR
1282 */
1283 fep->phy_speed = ((((MCF_CLK / 4) / (2500000 / 10)) + 5) / 10) * 2;
1284 fecp->fec_mii_speed = fep->phy_speed;
1285
1286 fec_restart(dev, 0);
1287}
1288
1289static void __inline__ fec_get_mac(struct net_device *dev)
1290{
1291 struct fec_enet_private *fep = netdev_priv(dev);
1292 volatile fec_t *fecp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001293 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295 fecp = fep->hwp;
1296
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001297 if (FEC_FLASHMAC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 /*
1299 * Get MAC address from FLASH.
1300 * If it is all 1's or 0's, use the default.
1301 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001302 iap = (unsigned char *)FEC_FLASHMAC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1304 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1305 iap = fec_mac_default;
1306 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1307 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1308 iap = fec_mac_default;
1309 } else {
1310 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1311 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1312 iap = &tmpaddr[0];
1313 }
1314
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001315 memcpy(dev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 /* Adjust MAC if using default MAC address */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001318 if (iap == fec_mac_default)
1319 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320}
1321
1322static void __inline__ fec_enable_phy_intr(void)
1323{
1324}
1325
1326static void __inline__ fec_disable_phy_intr(void)
1327{
1328 volatile unsigned long *icrp;
1329 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001330 *icrp = 0x08000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
1333static void __inline__ fec_phy_ack_intr(void)
1334{
1335 volatile unsigned long *icrp;
1336 /* Acknowledge the interrupt */
1337 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001338 *icrp = 0x0d000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
1341static void __inline__ fec_localhw_setup(void)
1342{
1343}
1344
1345/*
1346 * Do not need to make region uncached on 5272.
1347 */
1348static void __inline__ fec_uncache(unsigned long addr)
1349{
1350}
1351
1352/* ------------------------------------------------------------------------- */
1353
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001354#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356/*
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001357 * Code specific to Coldfire 5230/5231/5232/5234/5235,
1358 * the 5270/5271/5274/5275 and 5280/5282 setups.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 */
1360static void __inline__ fec_request_intrs(struct net_device *dev)
1361{
1362 struct fec_enet_private *fep;
1363 int b;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001364 static const struct idesc {
1365 char *name;
1366 unsigned short irq;
1367 } *idp, id[] = {
1368 { "fec(TXF)", 23 },
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001369 { "fec(RXF)", 27 },
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001370 { "fec(MII)", 29 },
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001371 { NULL },
1372 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 fep = netdev_priv(dev);
1375 b = (fep->index) ? 128 : 64;
1376
1377 /* Setup interrupt handlers. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001378 for (idp = id; idp->name; idp++) {
Greg Ungerer0a504772008-03-04 16:52:01 +10001379 if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name, dev) != 0)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001380 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
1384 {
1385 volatile unsigned char *icrp;
1386 volatile unsigned long *imrp;
Willson Callan83901fc2006-06-27 13:13:44 +10001387 int i, ilip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 b = (fep->index) ? MCFICM_INTC1 : MCFICM_INTC0;
1390 icrp = (volatile unsigned char *) (MCF_IPSBAR + b +
1391 MCFINTC_ICR0);
Willson Callan83901fc2006-06-27 13:13:44 +10001392 for (i = 23, ilip = 0x28; (i < 36); i++)
1393 icrp[i] = ilip--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
1396 MCFINTC_IMRH);
1397 *imrp &= ~0x0000000f;
1398 imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
1399 MCFINTC_IMRL);
1400 *imrp &= ~0xff800001;
1401 }
1402
1403#if defined(CONFIG_M528x)
1404 /* Set up gpio outputs for MII lines */
1405 {
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001406 volatile u16 *gpio_paspar;
1407 volatile u8 *gpio_pehlpar;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001408
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001409 gpio_paspar = (volatile u16 *) (MCF_IPSBAR + 0x100056);
1410 gpio_pehlpar = (volatile u16 *) (MCF_IPSBAR + 0x100058);
1411 *gpio_paspar |= 0x0f00;
1412 *gpio_pehlpar = 0xc0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 }
1414#endif
Mike Cruseb8a94b32007-07-30 16:29:29 +10001415
1416#if defined(CONFIG_M527x)
1417 /* Set up gpio outputs for MII lines */
1418 {
1419 volatile u8 *gpio_par_fec;
1420 volatile u16 *gpio_par_feci2c;
1421
1422 gpio_par_feci2c = (volatile u16 *)(MCF_IPSBAR + 0x100082);
1423 /* Set up gpio outputs for FEC0 MII lines */
1424 gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100078);
1425
1426 *gpio_par_feci2c |= 0x0f00;
1427 *gpio_par_fec |= 0xc0;
1428
1429#if defined(CONFIG_FEC2)
1430 /* Set up gpio outputs for FEC1 MII lines */
1431 gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100079);
1432
1433 *gpio_par_feci2c |= 0x00a0;
1434 *gpio_par_fec |= 0xc0;
1435#endif /* CONFIG_FEC2 */
1436 }
1437#endif /* CONFIG_M527x */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
1440static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1441{
1442 volatile fec_t *fecp;
1443
1444 fecp = fep->hwp;
1445 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1446 fecp->fec_x_cntrl = 0x00;
1447
1448 /*
1449 * Set MII speed to 2.5 MHz
1450 * See 5282 manual section 17.5.4.7: MSCR
1451 */
1452 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1453 fecp->fec_mii_speed = fep->phy_speed;
1454
1455 fec_restart(dev, 0);
1456}
1457
1458static void __inline__ fec_get_mac(struct net_device *dev)
1459{
1460 struct fec_enet_private *fep = netdev_priv(dev);
1461 volatile fec_t *fecp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001462 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 fecp = fep->hwp;
1465
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001466 if (FEC_FLASHMAC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 /*
1468 * Get MAC address from FLASH.
1469 * If it is all 1's or 0's, use the default.
1470 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001471 iap = FEC_FLASHMAC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1473 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1474 iap = fec_mac_default;
1475 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1476 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1477 iap = fec_mac_default;
1478 } else {
1479 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1480 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1481 iap = &tmpaddr[0];
1482 }
1483
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001484 memcpy(dev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* Adjust MAC if using default MAC address */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001487 if (iap == fec_mac_default)
1488 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
1491static void __inline__ fec_enable_phy_intr(void)
1492{
1493}
1494
1495static void __inline__ fec_disable_phy_intr(void)
1496{
1497}
1498
1499static void __inline__ fec_phy_ack_intr(void)
1500{
1501}
1502
1503static void __inline__ fec_localhw_setup(void)
1504{
1505}
1506
1507/*
1508 * Do not need to make region uncached on 5272.
1509 */
1510static void __inline__ fec_uncache(unsigned long addr)
1511{
1512}
1513
1514/* ------------------------------------------------------------------------- */
1515
Greg Ungerer562d2f82005-11-07 14:09:50 +10001516#elif defined(CONFIG_M520x)
1517
1518/*
1519 * Code specific to Coldfire 520x
1520 */
1521static void __inline__ fec_request_intrs(struct net_device *dev)
1522{
1523 struct fec_enet_private *fep;
1524 int b;
1525 static const struct idesc {
1526 char *name;
1527 unsigned short irq;
1528 } *idp, id[] = {
1529 { "fec(TXF)", 23 },
Greg Ungerer562d2f82005-11-07 14:09:50 +10001530 { "fec(RXF)", 27 },
Greg Ungerer562d2f82005-11-07 14:09:50 +10001531 { "fec(MII)", 29 },
Greg Ungerer562d2f82005-11-07 14:09:50 +10001532 { NULL },
1533 };
1534
1535 fep = netdev_priv(dev);
1536 b = 64 + 13;
1537
1538 /* Setup interrupt handlers. */
1539 for (idp = id; idp->name; idp++) {
Greg Ungerer0a504772008-03-04 16:52:01 +10001540 if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name,dev) != 0)
Greg Ungerer562d2f82005-11-07 14:09:50 +10001541 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1542 }
1543
1544 /* Unmask interrupts at ColdFire interrupt controller */
1545 {
1546 volatile unsigned char *icrp;
1547 volatile unsigned long *imrp;
1548
1549 icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
1550 MCFINTC_ICR0);
1551 for (b = 36; (b < 49); b++)
1552 icrp[b] = 0x04;
1553 imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 +
1554 MCFINTC_IMRH);
1555 *imrp &= ~0x0001FFF0;
1556 }
1557 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FEC) |= 0xf0;
1558 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C) |= 0x0f;
1559}
1560
1561static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1562{
1563 volatile fec_t *fecp;
1564
1565 fecp = fep->hwp;
1566 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1567 fecp->fec_x_cntrl = 0x00;
1568
1569 /*
1570 * Set MII speed to 2.5 MHz
1571 * See 5282 manual section 17.5.4.7: MSCR
1572 */
1573 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1574 fecp->fec_mii_speed = fep->phy_speed;
1575
1576 fec_restart(dev, 0);
1577}
1578
1579static void __inline__ fec_get_mac(struct net_device *dev)
1580{
1581 struct fec_enet_private *fep = netdev_priv(dev);
1582 volatile fec_t *fecp;
1583 unsigned char *iap, tmpaddr[ETH_ALEN];
1584
1585 fecp = fep->hwp;
1586
1587 if (FEC_FLASHMAC) {
1588 /*
1589 * Get MAC address from FLASH.
1590 * If it is all 1's or 0's, use the default.
1591 */
1592 iap = FEC_FLASHMAC;
1593 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1594 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1595 iap = fec_mac_default;
1596 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1597 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1598 iap = fec_mac_default;
1599 } else {
1600 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1601 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1602 iap = &tmpaddr[0];
1603 }
1604
1605 memcpy(dev->dev_addr, iap, ETH_ALEN);
1606
1607 /* Adjust MAC if using default MAC address */
1608 if (iap == fec_mac_default)
1609 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1610}
1611
1612static void __inline__ fec_enable_phy_intr(void)
1613{
1614}
1615
1616static void __inline__ fec_disable_phy_intr(void)
1617{
1618}
1619
1620static void __inline__ fec_phy_ack_intr(void)
1621{
1622}
1623
1624static void __inline__ fec_localhw_setup(void)
1625{
1626}
1627
1628static void __inline__ fec_uncache(unsigned long addr)
1629{
1630}
1631
1632/* ------------------------------------------------------------------------- */
1633
Matt Waddel6b265292006-06-27 13:10:56 +10001634#elif defined(CONFIG_M532x)
1635/*
1636 * Code specific for M532x
1637 */
1638static void __inline__ fec_request_intrs(struct net_device *dev)
1639{
1640 struct fec_enet_private *fep;
1641 int b;
1642 static const struct idesc {
1643 char *name;
1644 unsigned short irq;
1645 } *idp, id[] = {
1646 { "fec(TXF)", 36 },
Matt Waddel6b265292006-06-27 13:10:56 +10001647 { "fec(RXF)", 40 },
Matt Waddel6b265292006-06-27 13:10:56 +10001648 { "fec(MII)", 42 },
Matt Waddel6b265292006-06-27 13:10:56 +10001649 { NULL },
1650 };
1651
1652 fep = netdev_priv(dev);
1653 b = (fep->index) ? 128 : 64;
1654
1655 /* Setup interrupt handlers. */
1656 for (idp = id; idp->name; idp++) {
Greg Ungerer0a504772008-03-04 16:52:01 +10001657 if (request_irq(b+idp->irq, fec_enet_interrupt, IRQF_DISABLED, idp->name,dev) != 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001658 printk("FEC: Could not allocate %s IRQ(%d)!\n",
Matt Waddel6b265292006-06-27 13:10:56 +10001659 idp->name, b+idp->irq);
1660 }
1661
1662 /* Unmask interrupts */
1663 MCF_INTC0_ICR36 = 0x2;
1664 MCF_INTC0_ICR37 = 0x2;
1665 MCF_INTC0_ICR38 = 0x2;
1666 MCF_INTC0_ICR39 = 0x2;
1667 MCF_INTC0_ICR40 = 0x2;
1668 MCF_INTC0_ICR41 = 0x2;
1669 MCF_INTC0_ICR42 = 0x2;
1670 MCF_INTC0_ICR43 = 0x2;
1671 MCF_INTC0_ICR44 = 0x2;
1672 MCF_INTC0_ICR45 = 0x2;
1673 MCF_INTC0_ICR46 = 0x2;
1674 MCF_INTC0_ICR47 = 0x2;
1675 MCF_INTC0_ICR48 = 0x2;
1676
1677 MCF_INTC0_IMRH &= ~(
1678 MCF_INTC_IMRH_INT_MASK36 |
1679 MCF_INTC_IMRH_INT_MASK37 |
1680 MCF_INTC_IMRH_INT_MASK38 |
1681 MCF_INTC_IMRH_INT_MASK39 |
1682 MCF_INTC_IMRH_INT_MASK40 |
1683 MCF_INTC_IMRH_INT_MASK41 |
1684 MCF_INTC_IMRH_INT_MASK42 |
1685 MCF_INTC_IMRH_INT_MASK43 |
1686 MCF_INTC_IMRH_INT_MASK44 |
1687 MCF_INTC_IMRH_INT_MASK45 |
1688 MCF_INTC_IMRH_INT_MASK46 |
1689 MCF_INTC_IMRH_INT_MASK47 |
1690 MCF_INTC_IMRH_INT_MASK48 );
1691
1692 /* Set up gpio outputs for MII lines */
1693 MCF_GPIO_PAR_FECI2C |= (0 |
1694 MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
1695 MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO);
1696 MCF_GPIO_PAR_FEC = (0 |
1697 MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC |
1698 MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC);
1699}
1700
1701static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1702{
1703 volatile fec_t *fecp;
1704
1705 fecp = fep->hwp;
1706 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1707 fecp->fec_x_cntrl = 0x00;
1708
1709 /*
1710 * Set MII speed to 2.5 MHz
1711 */
1712 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1713 fecp->fec_mii_speed = fep->phy_speed;
1714
1715 fec_restart(dev, 0);
1716}
1717
1718static void __inline__ fec_get_mac(struct net_device *dev)
1719{
1720 struct fec_enet_private *fep = netdev_priv(dev);
1721 volatile fec_t *fecp;
1722 unsigned char *iap, tmpaddr[ETH_ALEN];
1723
1724 fecp = fep->hwp;
1725
1726 if (FEC_FLASHMAC) {
1727 /*
1728 * Get MAC address from FLASH.
1729 * If it is all 1's or 0's, use the default.
1730 */
1731 iap = FEC_FLASHMAC;
1732 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1733 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1734 iap = fec_mac_default;
1735 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1736 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1737 iap = fec_mac_default;
1738 } else {
1739 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1740 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1741 iap = &tmpaddr[0];
1742 }
1743
1744 memcpy(dev->dev_addr, iap, ETH_ALEN);
1745
1746 /* Adjust MAC if using default MAC address */
1747 if (iap == fec_mac_default)
1748 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1749}
1750
1751static void __inline__ fec_enable_phy_intr(void)
1752{
1753}
1754
1755static void __inline__ fec_disable_phy_intr(void)
1756{
1757}
1758
1759static void __inline__ fec_phy_ack_intr(void)
1760{
1761}
1762
1763static void __inline__ fec_localhw_setup(void)
1764{
1765}
1766
1767/*
1768 * Do not need to make region uncached on 532x.
1769 */
1770static void __inline__ fec_uncache(unsigned long addr)
1771{
1772}
1773
1774/* ------------------------------------------------------------------------- */
1775
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777#else
1778
1779/*
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001780 * Code specific to the MPC860T setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 */
1782static void __inline__ fec_request_intrs(struct net_device *dev)
1783{
1784 volatile immap_t *immap;
1785
1786 immap = (immap_t *)IMAP_ADDR; /* pointer to internal registers */
1787
1788 if (request_8xxirq(FEC_INTERRUPT, fec_enet_interrupt, 0, "fec", dev) != 0)
1789 panic("Could not allocate FEC IRQ!");
1790
1791#ifdef CONFIG_RPXCLASSIC
1792 /* Make Port C, bit 15 an input that causes interrupts.
1793 */
1794 immap->im_ioport.iop_pcpar &= ~0x0001;
1795 immap->im_ioport.iop_pcdir &= ~0x0001;
1796 immap->im_ioport.iop_pcso &= ~0x0001;
1797 immap->im_ioport.iop_pcint |= 0x0001;
1798 cpm_install_handler(CPMVEC_PIO_PC15, mii_link_interrupt, dev);
1799
1800 /* Make LEDS reflect Link status.
1801 */
1802 *((uint *) RPX_CSR_ADDR) &= ~BCSR2_FETHLEDMODE;
1803#endif
1804#ifdef CONFIG_FADS
1805 if (request_8xxirq(SIU_IRQ2, mii_link_interrupt, 0, "mii", dev) != 0)
1806 panic("Could not allocate MII IRQ!");
1807#endif
1808}
1809
1810static void __inline__ fec_get_mac(struct net_device *dev)
1811{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 bd_t *bd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 bd = (bd_t *)__res;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001815 memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
1817#ifdef CONFIG_RPXCLASSIC
1818 /* The Embedded Planet boards have only one MAC address in
1819 * the EEPROM, but can have two Ethernet ports. For the
1820 * FEC port, we create another address by setting one of
1821 * the address bits above something that would have (up to
1822 * now) been allocated.
1823 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001824 dev->dev_adrd[3] |= 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
1827
1828static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1829{
1830 extern uint _get_IMMR(void);
1831 volatile immap_t *immap;
1832 volatile fec_t *fecp;
1833
1834 fecp = fep->hwp;
1835 immap = (immap_t *)IMAP_ADDR; /* pointer to internal registers */
1836
1837 /* Configure all of port D for MII.
1838 */
1839 immap->im_ioport.iop_pdpar = 0x1fff;
1840
1841 /* Bits moved from Rev. D onward.
1842 */
1843 if ((_get_IMMR() & 0xffff) < 0x0501)
1844 immap->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
1845 else
1846 immap->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 /* Set MII speed to 2.5 MHz
1849 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001850 fecp->fec_mii_speed = fep->phy_speed =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 ((bd->bi_busfreq * 1000000) / 2500000) & 0x7e;
1852}
1853
1854static void __inline__ fec_enable_phy_intr(void)
1855{
1856 volatile fec_t *fecp;
1857
1858 fecp = fep->hwp;
1859
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001860 /* Enable MII command finished interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 */
1862 fecp->fec_ivec = (FEC_INTERRUPT/2) << 29;
1863}
1864
1865static void __inline__ fec_disable_phy_intr(void)
1866{
1867}
1868
1869static void __inline__ fec_phy_ack_intr(void)
1870{
1871}
1872
1873static void __inline__ fec_localhw_setup(void)
1874{
1875 volatile fec_t *fecp;
1876
1877 fecp = fep->hwp;
1878 fecp->fec_r_hash = PKT_MAXBUF_SIZE;
1879 /* Enable big endian and don't care about SDMA FC.
1880 */
1881 fecp->fec_fun_code = 0x78000000;
1882}
1883
1884static void __inline__ fec_uncache(unsigned long addr)
1885{
1886 pte_t *pte;
1887 pte = va_to_pte(mem_addr);
1888 pte_val(*pte) |= _PAGE_NO_CACHE;
1889 flush_tlb_page(init_mm.mmap, mem_addr);
1890}
1891
1892#endif
1893
1894/* ------------------------------------------------------------------------- */
1895
1896static void mii_display_status(struct net_device *dev)
1897{
1898 struct fec_enet_private *fep = netdev_priv(dev);
1899 volatile uint *s = &(fep->phy_status);
1900
1901 if (!fep->link && !fep->old_link) {
1902 /* Link is still down - don't print anything */
1903 return;
1904 }
1905
1906 printk("%s: status: ", dev->name);
1907
1908 if (!fep->link) {
1909 printk("link down");
1910 } else {
1911 printk("link up");
1912
1913 switch(*s & PHY_STAT_SPMASK) {
1914 case PHY_STAT_100FDX: printk(", 100MBit Full Duplex"); break;
1915 case PHY_STAT_100HDX: printk(", 100MBit Half Duplex"); break;
1916 case PHY_STAT_10FDX: printk(", 10MBit Full Duplex"); break;
1917 case PHY_STAT_10HDX: printk(", 10MBit Half Duplex"); break;
1918 default:
1919 printk(", Unknown speed/duplex");
1920 }
1921
1922 if (*s & PHY_STAT_ANC)
1923 printk(", auto-negotiation complete");
1924 }
1925
1926 if (*s & PHY_STAT_FAULT)
1927 printk(", remote fault");
1928
1929 printk(".\n");
1930}
1931
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001932static void mii_display_config(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001934 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
1935 struct net_device *dev = fep->netdev;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001936 uint status = fep->phy_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
1938 /*
1939 ** When we get here, phy_task is already removed from
1940 ** the workqueue. It is thus safe to allow to reuse it.
1941 */
1942 fep->mii_phy_task_queued = 0;
1943 printk("%s: config: auto-negotiation ", dev->name);
1944
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001945 if (status & PHY_CONF_ANE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 printk("on");
1947 else
1948 printk("off");
1949
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001950 if (status & PHY_CONF_100FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 printk(", 100FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001952 if (status & PHY_CONF_100HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 printk(", 100HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001954 if (status & PHY_CONF_10FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 printk(", 10FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001956 if (status & PHY_CONF_10HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 printk(", 10HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001958 if (!(status & PHY_CONF_SPMASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 printk(", No speed/duplex selected?");
1960
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001961 if (status & PHY_CONF_LOOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 printk(", loopback enabled");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 printk(".\n");
1965
1966 fep->sequence_done = 1;
1967}
1968
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001969static void mii_relink(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001971 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
1972 struct net_device *dev = fep->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 int duplex;
1974
1975 /*
1976 ** When we get here, phy_task is already removed from
1977 ** the workqueue. It is thus safe to allow to reuse it.
1978 */
1979 fep->mii_phy_task_queued = 0;
1980 fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
1981 mii_display_status(dev);
1982 fep->old_link = fep->link;
1983
1984 if (fep->link) {
1985 duplex = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001986 if (fep->phy_status
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 & (PHY_STAT_100FDX | PHY_STAT_10FDX))
1988 duplex = 1;
1989 fec_restart(dev, duplex);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10001990 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 fec_stop(dev);
1992
1993#if 0
1994 enable_irq(fep->mii_irq);
1995#endif
1996
1997}
1998
1999/* mii_queue_relink is called in interrupt context from mii_link_interrupt */
2000static void mii_queue_relink(uint mii_reg, struct net_device *dev)
2001{
2002 struct fec_enet_private *fep = netdev_priv(dev);
2003
2004 /*
2005 ** We cannot queue phy_task twice in the workqueue. It
2006 ** would cause an endless loop in the workqueue.
2007 ** Fortunately, if the last mii_relink entry has not yet been
2008 ** executed now, it will do the job for the current interrupt,
2009 ** which is just what we want.
2010 */
2011 if (fep->mii_phy_task_queued)
2012 return;
2013
2014 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002015 INIT_WORK(&fep->phy_task, mii_relink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 schedule_work(&fep->phy_task);
2017}
2018
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002019/* mii_queue_config is called in interrupt context from fec_enet_mii */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020static void mii_queue_config(uint mii_reg, struct net_device *dev)
2021{
2022 struct fec_enet_private *fep = netdev_priv(dev);
2023
2024 if (fep->mii_phy_task_queued)
2025 return;
2026
2027 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002028 INIT_WORK(&fep->phy_task, mii_display_config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 schedule_work(&fep->phy_task);
2030}
2031
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002032phy_cmd_t const phy_cmd_relink[] = {
2033 { mk_mii_read(MII_REG_CR), mii_queue_relink },
2034 { mk_mii_end, }
2035 };
2036phy_cmd_t const phy_cmd_config[] = {
2037 { mk_mii_read(MII_REG_CR), mii_queue_config },
2038 { mk_mii_end, }
2039 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041/* Read remainder of PHY ID.
2042*/
2043static void
2044mii_discover_phy3(uint mii_reg, struct net_device *dev)
2045{
2046 struct fec_enet_private *fep;
2047 int i;
2048
2049 fep = netdev_priv(dev);
2050 fep->phy_id |= (mii_reg & 0xffff);
2051 printk("fec: PHY @ 0x%x, ID 0x%08x", fep->phy_addr, fep->phy_id);
2052
2053 for(i = 0; phy_info[i]; i++) {
2054 if(phy_info[i]->id == (fep->phy_id >> 4))
2055 break;
2056 }
2057
2058 if (phy_info[i])
2059 printk(" -- %s\n", phy_info[i]->name);
2060 else
2061 printk(" -- unknown PHY!\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 fep->phy = phy_info[i];
2064 fep->phy_id_done = 1;
2065}
2066
2067/* Scan all of the MII PHY addresses looking for someone to respond
2068 * with a valid ID. This usually happens quickly.
2069 */
2070static void
2071mii_discover_phy(uint mii_reg, struct net_device *dev)
2072{
2073 struct fec_enet_private *fep;
2074 volatile fec_t *fecp;
2075 uint phytype;
2076
2077 fep = netdev_priv(dev);
2078 fecp = fep->hwp;
2079
2080 if (fep->phy_addr < 32) {
2081 if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 /* Got first part of ID, now get remainder.
2084 */
2085 fep->phy_id = phytype << 16;
2086 mii_queue(dev, mk_mii_read(MII_REG_PHYIR2),
2087 mii_discover_phy3);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10002088 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 fep->phy_addr++;
2090 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1),
2091 mii_discover_phy);
2092 }
2093 } else {
2094 printk("FEC: No PHY device found.\n");
2095 /* Disable external MII interface */
2096 fecp->fec_mii_speed = fep->phy_speed = 0;
2097 fec_disable_phy_intr();
2098 }
2099}
2100
2101/* This interrupt occurs when the PHY detects a link change.
2102*/
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10002103#ifdef HAVE_mii_link_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104#ifdef CONFIG_RPXCLASSIC
2105static void
2106mii_link_interrupt(void *dev_id)
2107#else
2108static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002109mii_link_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110#endif
2111{
2112 struct net_device *dev = dev_id;
2113 struct fec_enet_private *fep = netdev_priv(dev);
2114
2115 fec_phy_ack_intr();
2116
2117#if 0
2118 disable_irq(fep->mii_irq); /* disable now, enable later */
2119#endif
2120
2121 mii_do_cmd(dev, fep->phy->ack_int);
2122 mii_do_cmd(dev, phy_cmd_relink); /* restart and display status */
2123
2124 return IRQ_HANDLED;
2125}
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10002126#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128static int
2129fec_enet_open(struct net_device *dev)
2130{
2131 struct fec_enet_private *fep = netdev_priv(dev);
2132
2133 /* I should reset the ring buffers here, but I don't yet know
2134 * a simple way to do that.
2135 */
2136 fec_set_mac_address(dev);
2137
2138 fep->sequence_done = 0;
2139 fep->link = 0;
2140
2141 if (fep->phy) {
2142 mii_do_cmd(dev, fep->phy->ack_int);
2143 mii_do_cmd(dev, fep->phy->config);
2144 mii_do_cmd(dev, phy_cmd_config); /* display configuration */
2145
Matt Waddel6b265292006-06-27 13:10:56 +10002146 /* Poll until the PHY tells us its configuration
2147 * (not link state).
2148 * Request is initiated by mii_do_cmd above, but answer
2149 * comes by interrupt.
2150 * This should take about 25 usec per register at 2.5 MHz,
2151 * and we read approximately 5 registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 */
2153 while(!fep->sequence_done)
2154 schedule();
2155
2156 mii_do_cmd(dev, fep->phy->startup);
2157
2158 /* Set the initial link state to true. A lot of hardware
2159 * based on this device does not implement a PHY interrupt,
2160 * so we are never notified of link change.
2161 */
2162 fep->link = 1;
2163 } else {
2164 fep->link = 1; /* lets just try it and see */
2165 /* no phy, go full duplex, it's most likely a hub chip */
2166 fec_restart(dev, 1);
2167 }
2168
2169 netif_start_queue(dev);
2170 fep->opened = 1;
2171 return 0; /* Success */
2172}
2173
2174static int
2175fec_enet_close(struct net_device *dev)
2176{
2177 struct fec_enet_private *fep = netdev_priv(dev);
2178
2179 /* Don't know what to do yet.
2180 */
2181 fep->opened = 0;
2182 netif_stop_queue(dev);
2183 fec_stop(dev);
2184
2185 return 0;
2186}
2187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188/* Set or clear the multicast filter for this adaptor.
2189 * Skeleton taken from sunlance driver.
2190 * The CPM Ethernet implementation allows Multicast as well as individual
2191 * MAC address filtering. Some of the drivers check to make sure it is
2192 * a group multicast address, and discard those that are not. I guess I
2193 * will do the same for now, but just remove the test if you want
2194 * individual filtering as well (do the upper net layers want or support
2195 * this kind of feature?).
2196 */
2197
2198#define HASH_BITS 6 /* #bits in hash */
2199#define CRC32_POLY 0xEDB88320
2200
2201static void set_multicast_list(struct net_device *dev)
2202{
2203 struct fec_enet_private *fep;
2204 volatile fec_t *ep;
2205 struct dev_mc_list *dmi;
2206 unsigned int i, j, bit, data, crc;
2207 unsigned char hash;
2208
2209 fep = netdev_priv(dev);
2210 ep = fep->hwp;
2211
2212 if (dev->flags&IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 ep->fec_r_cntrl |= 0x0008;
2214 } else {
2215
2216 ep->fec_r_cntrl &= ~0x0008;
2217
2218 if (dev->flags & IFF_ALLMULTI) {
2219 /* Catch all multicast addresses, so set the
2220 * filter to all 1's.
2221 */
Greg Ungerercc462f72008-05-01 13:35:34 +10002222 ep->fec_grp_hash_table_high = 0xffffffff;
2223 ep->fec_grp_hash_table_low = 0xffffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 } else {
2225 /* Clear filter and add the addresses in hash register.
2226 */
Greg Ungerercc462f72008-05-01 13:35:34 +10002227 ep->fec_grp_hash_table_high = 0;
2228 ep->fec_grp_hash_table_low = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002229
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 dmi = dev->mc_list;
2231
2232 for (j = 0; j < dev->mc_count; j++, dmi = dmi->next)
2233 {
2234 /* Only support group multicast for now.
2235 */
2236 if (!(dmi->dmi_addr[0] & 1))
2237 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 /* calculate crc32 value of mac address
2240 */
2241 crc = 0xffffffff;
2242
2243 for (i = 0; i < dmi->dmi_addrlen; i++)
2244 {
2245 data = dmi->dmi_addr[i];
2246 for (bit = 0; bit < 8; bit++, data >>= 1)
2247 {
2248 crc = (crc >> 1) ^
2249 (((crc ^ data) & 1) ? CRC32_POLY : 0);
2250 }
2251 }
2252
2253 /* only upper 6 bits (HASH_BITS) are used
2254 which point to specific bit in he hash registers
2255 */
2256 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 if (hash > 31)
Greg Ungerercc462f72008-05-01 13:35:34 +10002259 ep->fec_grp_hash_table_high |= 1 << (hash - 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 else
Greg Ungerercc462f72008-05-01 13:35:34 +10002261 ep->fec_grp_hash_table_low |= 1 << hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 }
2263 }
2264 }
2265}
2266
2267/* Set a MAC change in hardware.
2268 */
2269static void
2270fec_set_mac_address(struct net_device *dev)
2271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 volatile fec_t *fecp;
2273
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002274 fecp = ((struct fec_enet_private *)netdev_priv(dev))->hwp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 /* Set station address. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002277 fecp->fec_addr_low = dev->dev_addr[3] | (dev->dev_addr[2] << 8) |
2278 (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24);
2279 fecp->fec_addr_high = (dev->dev_addr[5] << 16) |
2280 (dev->dev_addr[4] << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282}
2283
2284/* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
2285 */
2286 /*
2287 * XXX: We need to clean up on failure exits here.
2288 */
2289int __init fec_enet_init(struct net_device *dev)
2290{
2291 struct fec_enet_private *fep = netdev_priv(dev);
2292 unsigned long mem_addr;
2293 volatile cbd_t *bdp;
2294 cbd_t *cbd_base;
2295 volatile fec_t *fecp;
2296 int i, j;
2297 static int index = 0;
2298
2299 /* Only allow us to be probed once. */
2300 if (index >= FEC_MAX_PORTS)
2301 return -ENXIO;
2302
Greg Ungerer562d2f82005-11-07 14:09:50 +10002303 /* Allocate memory for buffer descriptors.
2304 */
2305 mem_addr = __get_free_page(GFP_KERNEL);
2306 if (mem_addr == 0) {
2307 printk("FEC: allocate descriptor memory failed?\n");
2308 return -ENOMEM;
2309 }
2310
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 /* Create an Ethernet device instance.
2312 */
2313 fecp = (volatile fec_t *) fec_hw[index];
2314
2315 fep->index = index;
2316 fep->hwp = fecp;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002317 fep->netdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
2319 /* Whack a reset. We should wait for this.
2320 */
2321 fecp->fec_ecntrl = 1;
2322 udelay(10);
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 /* Set the Ethernet address. If using multiple Enets on the 8xx,
2325 * this needs some work to get unique addresses.
2326 *
2327 * This is our default MAC address unless the user changes
2328 * it via eth_mac_addr (our dev->set_mac_addr handler).
2329 */
2330 fec_get_mac(dev);
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 cbd_base = (cbd_t *)mem_addr;
2333 /* XXX: missing check for allocation failure */
2334
2335 fec_uncache(mem_addr);
2336
2337 /* Set receive and transmit descriptor base.
2338 */
2339 fep->rx_bd_base = cbd_base;
2340 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
2341
2342 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
2343 fep->cur_rx = fep->rx_bd_base;
2344
2345 fep->skb_cur = fep->skb_dirty = 0;
2346
2347 /* Initialize the receive buffer descriptors.
2348 */
2349 bdp = fep->rx_bd_base;
2350 for (i=0; i<FEC_ENET_RX_PAGES; i++) {
2351
2352 /* Allocate a page.
2353 */
2354 mem_addr = __get_free_page(GFP_KERNEL);
2355 /* XXX: missing check for allocation failure */
2356
2357 fec_uncache(mem_addr);
2358
2359 /* Initialize the BD for every fragment in the page.
2360 */
2361 for (j=0; j<FEC_ENET_RX_FRPPG; j++) {
2362 bdp->cbd_sc = BD_ENET_RX_EMPTY;
2363 bdp->cbd_bufaddr = __pa(mem_addr);
2364 mem_addr += FEC_ENET_RX_FRSIZE;
2365 bdp++;
2366 }
2367 }
2368
2369 /* Set the last buffer to wrap.
2370 */
2371 bdp--;
2372 bdp->cbd_sc |= BD_SC_WRAP;
2373
2374 /* ...and the same for transmmit.
2375 */
2376 bdp = fep->tx_bd_base;
2377 for (i=0, j=FEC_ENET_TX_FRPPG; i<TX_RING_SIZE; i++) {
2378 if (j >= FEC_ENET_TX_FRPPG) {
2379 mem_addr = __get_free_page(GFP_KERNEL);
2380 j = 1;
2381 } else {
2382 mem_addr += FEC_ENET_TX_FRSIZE;
2383 j++;
2384 }
2385 fep->tx_bounce[i] = (unsigned char *) mem_addr;
2386
2387 /* Initialize the BD for every fragment in the page.
2388 */
2389 bdp->cbd_sc = 0;
2390 bdp->cbd_bufaddr = 0;
2391 bdp++;
2392 }
2393
2394 /* Set the last buffer to wrap.
2395 */
2396 bdp--;
2397 bdp->cbd_sc |= BD_SC_WRAP;
2398
2399 /* Set receive and transmit descriptor base.
2400 */
2401 fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
2402 fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
2403
2404 /* Install our interrupt handlers. This varies depending on
2405 * the architecture.
2406 */
2407 fec_request_intrs(dev);
2408
Greg Ungerercc462f72008-05-01 13:35:34 +10002409 fecp->fec_grp_hash_table_high = 0;
2410 fecp->fec_grp_hash_table_low = 0;
Greg Ungerer562d2f82005-11-07 14:09:50 +10002411 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2412 fecp->fec_ecntrl = 2;
Matt Waddel6b265292006-06-27 13:10:56 +10002413 fecp->fec_r_des_active = 0;
Greg Ungerercc462f72008-05-01 13:35:34 +10002414#ifndef CONFIG_M5272
2415 fecp->fec_hash_table_high = 0;
2416 fecp->fec_hash_table_low = 0;
2417#endif
Greg Ungerer562d2f82005-11-07 14:09:50 +10002418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 dev->base_addr = (unsigned long)fecp;
2420
2421 /* The FEC Ethernet specific entries in the device structure. */
2422 dev->open = fec_enet_open;
2423 dev->hard_start_xmit = fec_enet_start_xmit;
2424 dev->tx_timeout = fec_timeout;
2425 dev->watchdog_timeo = TX_TIMEOUT;
2426 dev->stop = fec_enet_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 dev->set_multicast_list = set_multicast_list;
2428
2429 for (i=0; i<NMII-1; i++)
2430 mii_cmds[i].mii_next = &mii_cmds[i+1];
2431 mii_free = mii_cmds;
2432
2433 /* setup MII interface */
2434 fec_set_mii(dev, fep);
2435
Matt Waddel6b265292006-06-27 13:10:56 +10002436 /* Clear and enable interrupts */
2437 fecp->fec_ievent = 0xffc00000;
Greg Ungerer398ec922008-05-01 13:47:09 +10002438 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
Matt Waddel6b265292006-06-27 13:10:56 +10002439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 /* Queue up command to detect the PHY and initialize the
2441 * remainder of the interface.
2442 */
2443 fep->phy_id_done = 0;
2444 fep->phy_addr = 0;
2445 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
2446
2447 index++;
2448 return 0;
2449}
2450
2451/* This function is called to start or restart the FEC during a link
2452 * change. This only happens when switching between half and full
2453 * duplex.
2454 */
2455static void
2456fec_restart(struct net_device *dev, int duplex)
2457{
2458 struct fec_enet_private *fep;
2459 volatile cbd_t *bdp;
2460 volatile fec_t *fecp;
2461 int i;
2462
2463 fep = netdev_priv(dev);
2464 fecp = fep->hwp;
2465
2466 /* Whack a reset. We should wait for this.
2467 */
2468 fecp->fec_ecntrl = 1;
2469 udelay(10);
2470
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 /* Clear any outstanding interrupt.
2472 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002473 fecp->fec_ievent = 0xffc00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 fec_enable_phy_intr();
2475
2476 /* Set station address.
2477 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002478 fec_set_mac_address(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
2480 /* Reset all multicast.
2481 */
Greg Ungerercc462f72008-05-01 13:35:34 +10002482 fecp->fec_grp_hash_table_high = 0;
2483 fecp->fec_grp_hash_table_low = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
2485 /* Set maximum receive buffer size.
2486 */
2487 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2488
2489 fec_localhw_setup();
2490
2491 /* Set receive and transmit descriptor base.
2492 */
2493 fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
2494 fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
2495
2496 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
2497 fep->cur_rx = fep->rx_bd_base;
2498
2499 /* Reset SKB transmit buffers.
2500 */
2501 fep->skb_cur = fep->skb_dirty = 0;
2502 for (i=0; i<=TX_RING_MOD_MASK; i++) {
2503 if (fep->tx_skbuff[i] != NULL) {
2504 dev_kfree_skb_any(fep->tx_skbuff[i]);
2505 fep->tx_skbuff[i] = NULL;
2506 }
2507 }
2508
2509 /* Initialize the receive buffer descriptors.
2510 */
2511 bdp = fep->rx_bd_base;
2512 for (i=0; i<RX_RING_SIZE; i++) {
2513
2514 /* Initialize the BD for every fragment in the page.
2515 */
2516 bdp->cbd_sc = BD_ENET_RX_EMPTY;
2517 bdp++;
2518 }
2519
2520 /* Set the last buffer to wrap.
2521 */
2522 bdp--;
2523 bdp->cbd_sc |= BD_SC_WRAP;
2524
2525 /* ...and the same for transmmit.
2526 */
2527 bdp = fep->tx_bd_base;
2528 for (i=0; i<TX_RING_SIZE; i++) {
2529
2530 /* Initialize the BD for every fragment in the page.
2531 */
2532 bdp->cbd_sc = 0;
2533 bdp->cbd_bufaddr = 0;
2534 bdp++;
2535 }
2536
2537 /* Set the last buffer to wrap.
2538 */
2539 bdp--;
2540 bdp->cbd_sc |= BD_SC_WRAP;
2541
2542 /* Enable MII mode.
2543 */
2544 if (duplex) {
2545 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;/* MII enable */
2546 fecp->fec_x_cntrl = 0x04; /* FD enable */
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10002547 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 /* MII enable|No Rcv on Xmit */
2549 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x06;
2550 fecp->fec_x_cntrl = 0x00;
2551 }
2552 fep->full_duplex = duplex;
2553
2554 /* Set MII speed.
2555 */
2556 fecp->fec_mii_speed = fep->phy_speed;
2557
2558 /* And last, enable the transmit and receive processing.
2559 */
2560 fecp->fec_ecntrl = 2;
Matt Waddel6b265292006-06-27 13:10:56 +10002561 fecp->fec_r_des_active = 0;
2562
2563 /* Enable interrupts we wish to service.
2564 */
Greg Ungerer398ec922008-05-01 13:47:09 +10002565 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566}
2567
2568static void
2569fec_stop(struct net_device *dev)
2570{
2571 volatile fec_t *fecp;
2572 struct fec_enet_private *fep;
2573
2574 fep = netdev_priv(dev);
2575 fecp = fep->hwp;
2576
Philippe De Muyter677177c2006-06-27 13:05:33 +10002577 /*
2578 ** We cannot expect a graceful transmit stop without link !!!
2579 */
2580 if (fep->link)
2581 {
2582 fecp->fec_x_cntrl = 0x01; /* Graceful transmit stop */
2583 udelay(10);
2584 if (!(fecp->fec_ievent & FEC_ENET_GRA))
2585 printk("fec_stop : Graceful transmit stop did not complete !\n");
2586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
2588 /* Whack a reset. We should wait for this.
2589 */
2590 fecp->fec_ecntrl = 1;
2591 udelay(10);
2592
2593 /* Clear outstanding MII command interrupts.
2594 */
2595 fecp->fec_ievent = FEC_ENET_MII;
2596 fec_enable_phy_intr();
2597
2598 fecp->fec_imask = FEC_ENET_MII;
2599 fecp->fec_mii_speed = fep->phy_speed;
2600}
2601
2602static int __init fec_enet_module_init(void)
2603{
2604 struct net_device *dev;
Sebastian Siewiorc1d96152008-05-01 14:04:02 +10002605 int i, err;
Joe Perches0795af52007-10-03 17:59:30 -07002606 DECLARE_MAC_BUF(mac);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002607
2608 printk("FEC ENET Version 0.2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
2610 for (i = 0; (i < FEC_MAX_PORTS); i++) {
2611 dev = alloc_etherdev(sizeof(struct fec_enet_private));
2612 if (!dev)
2613 return -ENOMEM;
2614 err = fec_enet_init(dev);
2615 if (err) {
2616 free_netdev(dev);
2617 continue;
2618 }
2619 if (register_netdev(dev) != 0) {
2620 /* XXX: missing cleanup here */
2621 free_netdev(dev);
2622 return -EIO;
2623 }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002624
Joe Perches0795af52007-10-03 17:59:30 -07002625 printk("%s: ethernet %s\n",
2626 dev->name, print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 }
2628 return 0;
2629}
2630
2631module_init(fec_enet_module_init);
2632
2633MODULE_LICENSE("GPL");