blob: e0d875531e6e19327ba2fc4d29810dbb9659e8b3 [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
70/*
71 * Define the fixed address of the FEC hardware.
72 */
73static unsigned int fec_hw[] = {
74#if defined(CONFIG_M5272)
75 (MCF_MBAR + 0x840),
76#elif defined(CONFIG_M527x)
77 (MCF_MBAR + 0x1000),
78 (MCF_MBAR + 0x1800),
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +100079#elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 (MCF_MBAR + 0x1000),
Greg Ungerer562d2f82005-11-07 14:09:50 +100081#elif defined(CONFIG_M520x)
82 (MCF_MBAR+0x30000),
Matt Waddel6b265292006-06-27 13:10:56 +100083#elif defined(CONFIG_M532x)
84 (MCF_MBAR+0xfc030000),
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#else
86 &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
87#endif
88};
89
90static unsigned char fec_mac_default[] = {
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92};
93
94/*
95 * Some hardware gets it MAC address out of local flash memory.
96 * if this is non-zero then assume it is the address to get MAC from.
97 */
98#if defined(CONFIG_NETtel)
99#define FEC_FLASHMAC 0xf0006006
100#elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
101#define FEC_FLASHMAC 0xf0006000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#elif defined(CONFIG_CANCam)
103#define FEC_FLASHMAC 0xf0020000
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000104#elif defined (CONFIG_M5272C3)
105#define FEC_FLASHMAC (0xffe04000 + 4)
106#elif defined(CONFIG_MOD5272)
107#define FEC_FLASHMAC 0xffc0406b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#else
109#define FEC_FLASHMAC 0
110#endif
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* Forward declarations of some structures to support different PHYs
113*/
114
115typedef struct {
116 uint mii_data;
117 void (*funct)(uint mii_reg, struct net_device *dev);
118} phy_cmd_t;
119
120typedef struct {
121 uint id;
122 char *name;
123
124 const phy_cmd_t *config;
125 const phy_cmd_t *startup;
126 const phy_cmd_t *ack_int;
127 const phy_cmd_t *shutdown;
128} phy_info_t;
129
130/* The number of Tx and Rx buffers. These are allocated from the page
131 * pool. The code may assume these are power of two, so it it best
132 * to keep them that size.
133 * We don't need to allocate pages for the transmitter. We just use
134 * the skbuffer directly.
135 */
136#define FEC_ENET_RX_PAGES 8
137#define FEC_ENET_RX_FRSIZE 2048
138#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
139#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
140#define FEC_ENET_TX_FRSIZE 2048
141#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
142#define TX_RING_SIZE 16 /* Must be power of two */
143#define TX_RING_MOD_MASK 15 /* for this to work */
144
Greg Ungerer562d2f82005-11-07 14:09:50 +1000145#if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
Matt Waddel6b265292006-06-27 13:10:56 +1000146#error "FEC: descriptor ring size constants too large"
Greg Ungerer562d2f82005-11-07 14:09:50 +1000147#endif
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/* Interrupt events/masks.
150*/
151#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
152#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
153#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
154#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
155#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
156#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
157#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
158#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
159#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
160#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
161
162/* The FEC stores dest/src/type, data, and checksum for receive packets.
163 */
164#define PKT_MAXBUF_SIZE 1518
165#define PKT_MINBUF_SIZE 64
166#define PKT_MAXBLR_SIZE 1520
167
168
169/*
Matt Waddel6b265292006-06-27 13:10:56 +1000170 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 * size bits. Other FEC hardware does not, so we need to take that into
172 * account when setting it.
173 */
Greg Ungerer562d2f82005-11-07 14:09:50 +1000174#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
Matt Waddel6b265292006-06-27 13:10:56 +1000175 defined(CONFIG_M520x) || defined(CONFIG_M532x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
177#else
178#define OPT_FRAME_SIZE 0
179#endif
180
181/* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
182 * tx_bd_base always point to the base of the buffer descriptors. The
183 * cur_rx and cur_tx point to the currently available buffer.
184 * The dirty_tx tracks the current buffer that is being sent by the
185 * controller. The cur_tx and dirty_tx are equal under both completely
186 * empty and completely full conditions. The empty/ready indicator in
187 * the buffer descriptor determines the actual condition.
188 */
189struct fec_enet_private {
190 /* Hardware registers of the FEC device */
191 volatile fec_t *hwp;
192
Greg Ungerercb84d6e2007-07-30 16:29:09 +1000193 struct net_device *netdev;
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
196 unsigned char *tx_bounce[TX_RING_SIZE];
197 struct sk_buff* tx_skbuff[TX_RING_SIZE];
198 ushort skb_cur;
199 ushort skb_dirty;
200
201 /* CPM dual port RAM relative addresses.
202 */
203 cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
204 cbd_t *tx_bd_base;
205 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
206 cbd_t *dirty_tx; /* The ring entries to be free()ed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 uint tx_full;
208 spinlock_t lock;
209
210 uint phy_id;
211 uint phy_id_done;
212 uint phy_status;
213 uint phy_speed;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000214 phy_info_t const *phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 struct work_struct phy_task;
216
217 uint sequence_done;
218 uint mii_phy_task_queued;
219
220 uint phy_addr;
221
222 int index;
223 int opened;
224 int link;
225 int old_link;
226 int full_duplex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227};
228
229static int fec_enet_open(struct net_device *dev);
230static int fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
231static void fec_enet_mii(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100232static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static void fec_enet_tx(struct net_device *dev);
234static void fec_enet_rx(struct net_device *dev);
235static int fec_enet_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236static void set_multicast_list(struct net_device *dev);
237static void fec_restart(struct net_device *dev, int duplex);
238static void fec_stop(struct net_device *dev);
239static void fec_set_mac_address(struct net_device *dev);
240
241
242/* MII processing. We keep this as simple as possible. Requests are
243 * placed on the list (if there is room). When the request is finished
244 * by the MII, an optional function may be called.
245 */
246typedef struct mii_list {
247 uint mii_regval;
248 void (*mii_func)(uint val, struct net_device *dev);
249 struct mii_list *mii_next;
250} mii_list_t;
251
252#define NMII 20
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000253static mii_list_t mii_cmds[NMII];
254static mii_list_t *mii_free;
255static mii_list_t *mii_head;
256static mii_list_t *mii_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400258static int mii_queue(struct net_device *dev, int request,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 void (*func)(uint, struct net_device *));
260
261/* Make MII read/write commands for the FEC.
262*/
263#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
264#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
265 (VAL & 0xffff))
266#define mk_mii_end 0
267
268/* Transmitter timeout.
269*/
270#define TX_TIMEOUT (2*HZ)
271
272/* Register definitions for the PHY.
273*/
274
275#define MII_REG_CR 0 /* Control Register */
276#define MII_REG_SR 1 /* Status Register */
277#define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
278#define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400279#define MII_REG_ANAR 4 /* A-N Advertisement Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
281#define MII_REG_ANER 6 /* A-N Expansion Register */
282#define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
283#define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
284
285/* values for phy_status */
286
287#define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
288#define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
289#define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
290#define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400291#define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400293#define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295#define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
296#define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
297#define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
298#define PHY_STAT_SPMASK 0xf000 /* mask for speed */
299#define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400300#define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400302#define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304
305static int
306fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
307{
308 struct fec_enet_private *fep;
309 volatile fec_t *fecp;
310 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000311 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 fep = netdev_priv(dev);
314 fecp = (volatile fec_t*)dev->base_addr;
315
316 if (!fep->link) {
317 /* Link is down or autonegotiation is in progress. */
318 return 1;
319 }
320
321 /* Fill in a Tx ring entry */
322 bdp = fep->cur_tx;
323
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000324 status = bdp->cbd_sc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#ifndef final_version
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000326 if (status & BD_ENET_TX_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 /* Ooops. All transmit buffers are full. Bail out.
328 * This should not happen, since dev->tbusy should be set.
329 */
330 printk("%s: tx queue full!.\n", dev->name);
331 return 1;
332 }
333#endif
334
335 /* Clear all of the status flags.
336 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000337 status &= ~BD_ENET_TX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /* Set buffer length and buffer pointer.
340 */
341 bdp->cbd_bufaddr = __pa(skb->data);
342 bdp->cbd_datlen = skb->len;
343
344 /*
345 * On some FEC implementations data must be aligned on
346 * 4-byte boundaries. Use bounce buffers to copy data
347 * and get it aligned. Ugh.
348 */
349 if (bdp->cbd_bufaddr & 0x3) {
350 unsigned int index;
351 index = bdp - fep->tx_bd_base;
352 memcpy(fep->tx_bounce[index], (void *) bdp->cbd_bufaddr, bdp->cbd_datlen);
353 bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
354 }
355
356 /* Save skb pointer.
357 */
358 fep->tx_skbuff[fep->skb_cur] = skb;
359
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700360 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* Push the data cache so the CPM does not get stale memory
364 * data.
365 */
366 flush_dcache_range((unsigned long)skb->data,
367 (unsigned long)skb->data + skb->len);
368
369 spin_lock_irq(&fep->lock);
370
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000371 /* Send it on its way. Tell FEC it's ready, interrupt when done,
372 * it's the last BD of the frame, and to put the CRC on the end.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 */
374
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000375 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000377 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 dev->trans_start = jiffies;
380
381 /* Trigger transmission start */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000382 fecp->fec_x_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 /* If this was the last BD in the ring, start at the beginning again.
385 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000386 if (status & BD_ENET_TX_WRAP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 bdp = fep->tx_bd_base;
388 } else {
389 bdp++;
390 }
391
392 if (bdp == fep->dirty_tx) {
393 fep->tx_full = 1;
394 netif_stop_queue(dev);
395 }
396
397 fep->cur_tx = (cbd_t *)bdp;
398
399 spin_unlock_irq(&fep->lock);
400
401 return 0;
402}
403
404static void
405fec_timeout(struct net_device *dev)
406{
407 struct fec_enet_private *fep = netdev_priv(dev);
408
409 printk("%s: transmit timed out.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700410 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#ifndef final_version
412 {
413 int i;
414 cbd_t *bdp;
415
416 printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
417 (unsigned long)fep->cur_tx, fep->tx_full ? " (full)" : "",
418 (unsigned long)fep->dirty_tx,
419 (unsigned long)fep->cur_rx);
420
421 bdp = fep->tx_bd_base;
422 printk(" tx: %u buffers\n", TX_RING_SIZE);
423 for (i = 0 ; i < TX_RING_SIZE; i++) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400424 printk(" %08x: %04x %04x %08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 (uint) bdp,
426 bdp->cbd_sc,
427 bdp->cbd_datlen,
428 (int) bdp->cbd_bufaddr);
429 bdp++;
430 }
431
432 bdp = fep->rx_bd_base;
433 printk(" rx: %lu buffers\n", (unsigned long) RX_RING_SIZE);
434 for (i = 0 ; i < RX_RING_SIZE; i++) {
435 printk(" %08x: %04x %04x %08x\n",
436 (uint) bdp,
437 bdp->cbd_sc,
438 bdp->cbd_datlen,
439 (int) bdp->cbd_bufaddr);
440 bdp++;
441 }
442 }
443#endif
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000444 fec_restart(dev, fep->full_duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 netif_wake_queue(dev);
446}
447
448/* The interrupt handler.
449 * This is called from the MPC core interrupt.
450 */
451static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100452fec_enet_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 struct net_device *dev = dev_id;
455 volatile fec_t *fecp;
456 uint int_events;
457 int handled = 0;
458
459 fecp = (volatile fec_t*)dev->base_addr;
460
461 /* Get the interrupt events that caused us to be here.
462 */
463 while ((int_events = fecp->fec_ievent) != 0) {
464 fecp->fec_ievent = int_events;
465
466 /* Handle receive event in its own function.
467 */
468 if (int_events & FEC_ENET_RXF) {
469 handled = 1;
470 fec_enet_rx(dev);
471 }
472
473 /* Transmit OK, or non-fatal error. Update the buffer
474 descriptors. FEC handles all errors, we just discover
475 them as part of the transmit process.
476 */
477 if (int_events & FEC_ENET_TXF) {
478 handled = 1;
479 fec_enet_tx(dev);
480 }
481
482 if (int_events & FEC_ENET_MII) {
483 handled = 1;
484 fec_enet_mii(dev);
485 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488 return IRQ_RETVAL(handled);
489}
490
491
492static void
493fec_enet_tx(struct net_device *dev)
494{
495 struct fec_enet_private *fep;
496 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000497 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 struct sk_buff *skb;
499
500 fep = netdev_priv(dev);
501 spin_lock(&fep->lock);
502 bdp = fep->dirty_tx;
503
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000504 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (bdp == fep->cur_tx && fep->tx_full == 0) break;
506
507 skb = fep->tx_skbuff[fep->skb_dirty];
508 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000509 if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 BD_ENET_TX_RL | BD_ENET_TX_UN |
511 BD_ENET_TX_CSL)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700512 dev->stats.tx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000513 if (status & BD_ENET_TX_HB) /* No heartbeat */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700514 dev->stats.tx_heartbeat_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000515 if (status & BD_ENET_TX_LC) /* Late collision */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700516 dev->stats.tx_window_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000517 if (status & BD_ENET_TX_RL) /* Retrans limit */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700518 dev->stats.tx_aborted_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000519 if (status & BD_ENET_TX_UN) /* Underrun */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700520 dev->stats.tx_fifo_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000521 if (status & BD_ENET_TX_CSL) /* Carrier lost */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700522 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700524 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
526
527#ifndef final_version
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000528 if (status & BD_ENET_TX_READY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 printk("HEY! Enet xmit interrupt and TX_READY.\n");
530#endif
531 /* Deferred means some collisions occurred during transmit,
532 * but we eventually sent the packet OK.
533 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000534 if (status & BD_ENET_TX_DEF)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700535 dev->stats.collisions++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 /* Free the sk buffer associated with this last transmit.
538 */
539 dev_kfree_skb_any(skb);
540 fep->tx_skbuff[fep->skb_dirty] = NULL;
541 fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /* Update pointer to next buffer descriptor to be transmitted.
544 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000545 if (status & BD_ENET_TX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 bdp = fep->tx_bd_base;
547 else
548 bdp++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /* Since we have freed up a buffer, the ring is no longer
551 * full.
552 */
553 if (fep->tx_full) {
554 fep->tx_full = 0;
555 if (netif_queue_stopped(dev))
556 netif_wake_queue(dev);
557 }
558 }
559 fep->dirty_tx = (cbd_t *)bdp;
560 spin_unlock(&fep->lock);
561}
562
563
564/* During a receive, the cur_rx points to the current incoming buffer.
565 * When we update through the ring, if the next incoming buffer has
566 * not been given to the system, we just set the empty indicator,
567 * effectively tossing the packet.
568 */
569static void
570fec_enet_rx(struct net_device *dev)
571{
572 struct fec_enet_private *fep;
573 volatile fec_t *fecp;
574 volatile cbd_t *bdp;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000575 unsigned short status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 struct sk_buff *skb;
577 ushort pkt_len;
578 __u8 *data;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400579
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000580#ifdef CONFIG_M532x
581 flush_cache_all();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 fep = netdev_priv(dev);
585 fecp = (volatile fec_t*)dev->base_addr;
586
587 /* First, grab all of the stats for the incoming packet.
588 * These get messed up if we get called due to a busy condition.
589 */
590 bdp = fep->cur_rx;
591
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000592while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594#ifndef final_version
595 /* Since we have allocated space to hold a complete frame,
596 * the last indicator should be set.
597 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000598 if ((status & BD_ENET_RX_LAST) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 printk("FEC ENET: rcv is not +last\n");
600#endif
601
602 if (!fep->opened)
603 goto rx_processing_done;
604
605 /* Check for errors. */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000606 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 BD_ENET_RX_CR | BD_ENET_RX_OV)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700608 dev->stats.rx_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000609 if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /* Frame too long or too short. */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700611 dev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 }
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000613 if (status & BD_ENET_RX_NO) /* Frame alignment */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700614 dev->stats.rx_frame_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000615 if (status & BD_ENET_RX_CR) /* CRC Error */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700616 dev->stats.rx_crc_errors++;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000617 if (status & BD_ENET_RX_OV) /* FIFO overrun */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700618 dev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
621 /* Report late collisions as a frame error.
622 * On this error, the BD is closed, but we don't know what we
623 * have in the buffer. So, just drop this frame on the floor.
624 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000625 if (status & BD_ENET_RX_CL) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700626 dev->stats.rx_errors++;
627 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 goto rx_processing_done;
629 }
630
631 /* Process the incoming frame.
632 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700633 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 pkt_len = bdp->cbd_datlen;
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700635 dev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 data = (__u8*)__va(bdp->cbd_bufaddr);
637
638 /* This does 16 byte alignment, exactly what we need.
639 * The packet length includes FCS, but we don't want to
640 * include that when passing upstream as it messes up
641 * bridging applications.
642 */
643 skb = dev_alloc_skb(pkt_len-4);
644
645 if (skb == NULL) {
646 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700647 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 skb_put(skb,pkt_len-4); /* Make room */
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700650 skb_copy_to_linear_data(skb, data, pkt_len-4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 skb->protocol=eth_type_trans(skb,dev);
652 netif_rx(skb);
653 }
654 rx_processing_done:
655
656 /* Clear the status flags for this buffer.
657 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000658 status &= ~BD_ENET_RX_STATS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 /* Mark the buffer empty.
661 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000662 status |= BD_ENET_RX_EMPTY;
663 bdp->cbd_sc = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 /* Update BD pointer to next entry.
666 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000667 if (status & BD_ENET_RX_WRAP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 bdp = fep->rx_bd_base;
669 else
670 bdp++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#if 1
673 /* Doing this here will keep the FEC running while we process
674 * incoming frames. On a heavily loaded network, we should be
675 * able to keep up at the expense of system resources.
676 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000677 fecp->fec_r_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#endif
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000679 } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 fep->cur_rx = (cbd_t *)bdp;
681
682#if 0
683 /* Doing this here will allow us to process all frames in the
684 * ring before the FEC is allowed to put more there. On a heavily
685 * loaded network, some frames may be lost. Unfortunately, this
686 * increases the interrupt overhead since we can potentially work
687 * our way back to the interrupt return only to come right back
688 * here.
689 */
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000690 fecp->fec_r_des_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#endif
692}
693
694
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000695/* called from interrupt context */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696static void
697fec_enet_mii(struct net_device *dev)
698{
699 struct fec_enet_private *fep;
700 volatile fec_t *ep;
701 mii_list_t *mip;
702 uint mii_reg;
703
704 fep = netdev_priv(dev);
705 ep = fep->hwp;
706 mii_reg = ep->fec_mii_data;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000707
708 spin_lock(&fep->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if ((mip = mii_head) == NULL) {
711 printk("MII and no head!\n");
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000712 goto unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
715 if (mip->mii_func != NULL)
716 (*(mip->mii_func))(mii_reg, dev);
717
718 mii_head = mip->mii_next;
719 mip->mii_next = mii_free;
720 mii_free = mip;
721
722 if ((mip = mii_head) != NULL)
723 ep->fec_mii_data = mip->mii_regval;
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000724
725unlock:
726 spin_unlock(&fep->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
729static int
730mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_device *))
731{
732 struct fec_enet_private *fep;
733 unsigned long flags;
734 mii_list_t *mip;
735 int retval;
736
737 /* Add PHY address to register command.
738 */
739 fep = netdev_priv(dev);
740 regval |= fep->phy_addr << 23;
741
742 retval = 0;
743
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000744 spin_lock_irqsave(&fep->lock,flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 if ((mip = mii_free) != NULL) {
747 mii_free = mip->mii_next;
748 mip->mii_regval = regval;
749 mip->mii_func = func;
750 mip->mii_next = NULL;
751 if (mii_head) {
752 mii_tail->mii_next = mip;
753 mii_tail = mip;
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000754 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 mii_head = mii_tail = mip;
756 fep->hwp->fec_mii_data = regval;
757 }
Philippe De Muyterf909b1e2007-10-23 14:37:54 +1000758 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 retval = 1;
760 }
761
Greg Ungerer0e702ab2006-06-27 13:19:33 +1000762 spin_unlock_irqrestore(&fep->lock,flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 return(retval);
765}
766
767static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
768{
769 int k;
770
771 if(!c)
772 return;
773
774 for(k = 0; (c+k)->mii_data != mk_mii_end; k++) {
775 mii_queue(dev, (c+k)->mii_data, (c+k)->funct);
776 }
777}
778
779static void mii_parse_sr(uint mii_reg, struct net_device *dev)
780{
781 struct fec_enet_private *fep = netdev_priv(dev);
782 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000783 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000785 status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 if (mii_reg & 0x0004)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000788 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 if (mii_reg & 0x0010)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000790 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000792 status |= PHY_STAT_ANC;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000793 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
796static void mii_parse_cr(uint mii_reg, struct net_device *dev)
797{
798 struct fec_enet_private *fep = netdev_priv(dev);
799 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000800 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000802 status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000805 status |= PHY_CONF_ANE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (mii_reg & 0x4000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000807 status |= PHY_CONF_LOOP;
808 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static void mii_parse_anar(uint mii_reg, struct net_device *dev)
812{
813 struct fec_enet_private *fep = netdev_priv(dev);
814 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000815 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000817 status = *s & ~(PHY_CONF_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 if (mii_reg & 0x0020)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000820 status |= PHY_CONF_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (mii_reg & 0x0040)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000822 status |= PHY_CONF_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000824 status |= PHY_CONF_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (mii_reg & 0x00100)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000826 status |= PHY_CONF_100FDX;
827 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
830/* ------------------------------------------------------------------------- */
831/* The Level one LXT970 is used by many boards */
832
833#define MII_LXT970_MIRROR 16 /* Mirror register */
834#define MII_LXT970_IER 17 /* Interrupt Enable Register */
835#define MII_LXT970_ISR 18 /* Interrupt Status Register */
836#define MII_LXT970_CONFIG 19 /* Configuration Register */
837#define MII_LXT970_CSR 20 /* Chip Status Register */
838
839static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev)
840{
841 struct fec_enet_private *fep = netdev_priv(dev);
842 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000843 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000845 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (mii_reg & 0x0800) {
847 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000848 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000850 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 } else {
852 if (mii_reg & 0x1000)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000853 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000855 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000857 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000860static phy_cmd_t const phy_cmd_lxt970_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 { mk_mii_read(MII_REG_CR), mii_parse_cr },
862 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
863 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000864 };
865static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 { mk_mii_write(MII_LXT970_IER, 0x0002), NULL },
867 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
868 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000869 };
870static phy_cmd_t const phy_cmd_lxt970_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 /* read SR and ISR to acknowledge */
872 { mk_mii_read(MII_REG_SR), mii_parse_sr },
873 { mk_mii_read(MII_LXT970_ISR), NULL },
874
875 /* find out the current status */
876 { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr },
877 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000878 };
879static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 { mk_mii_write(MII_LXT970_IER, 0x0000), NULL },
881 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000882 };
883static phy_info_t const phy_info_lxt970 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400884 .id = 0x07810000,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000885 .name = "LXT970",
886 .config = phy_cmd_lxt970_config,
887 .startup = phy_cmd_lxt970_startup,
888 .ack_int = phy_cmd_lxt970_ack_int,
889 .shutdown = phy_cmd_lxt970_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/* ------------------------------------------------------------------------- */
893/* The Level one LXT971 is used on some of my custom boards */
894
895/* register definitions for the 971 */
896
897#define MII_LXT971_PCR 16 /* Port Control Register */
898#define MII_LXT971_SR2 17 /* Status Register 2 */
899#define MII_LXT971_IER 18 /* Interrupt Enable Register */
900#define MII_LXT971_ISR 19 /* Interrupt Status Register */
901#define MII_LXT971_LCR 20 /* LED Control Register */
902#define MII_LXT971_TCR 30 /* Transmit Control Register */
903
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400904/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 * I had some nice ideas of running the MDIO faster...
906 * The 971 should support 8MHz and I tried it, but things acted really
907 * weird, so 2.5 MHz ought to be enough for anyone...
908 */
909
910static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
911{
912 struct fec_enet_private *fep = netdev_priv(dev);
913 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000914 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000916 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 if (mii_reg & 0x0400) {
919 fep->link = 1;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000920 status |= PHY_STAT_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 } else {
922 fep->link = 0;
923 }
924 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000925 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if (mii_reg & 0x4000) {
927 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000928 status |= PHY_STAT_100FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000930 status |= PHY_STAT_100HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 } else {
932 if (mii_reg & 0x0200)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000933 status |= PHY_STAT_10FDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000935 status |= PHY_STAT_10HDX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937 if (mii_reg & 0x0008)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000938 status |= PHY_STAT_FAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000940 *s = status;
941}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400942
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000943static phy_cmd_t const phy_cmd_lxt971_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400944 /* limit to 10MBit because my prototype board
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 * doesn't work with 100. */
946 { mk_mii_read(MII_REG_CR), mii_parse_cr },
947 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
948 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
949 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000950 };
951static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL },
953 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
954 { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */
955 /* Somehow does the 971 tell me that the link is down
956 * the first read after power-up.
957 * read here to get a valid value in ack_int */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400958 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000960 };
961static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
962 /* acknowledge the int before reading status ! */
963 { mk_mii_read(MII_LXT971_ISR), NULL },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /* find out the current status */
965 { mk_mii_read(MII_REG_SR), mii_parse_sr },
966 { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000968 };
969static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 { mk_mii_write(MII_LXT971_IER, 0x0000), NULL },
971 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000972 };
973static phy_info_t const phy_info_lxt971 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400974 .id = 0x0001378e,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000975 .name = "LXT971",
976 .config = phy_cmd_lxt971_config,
977 .startup = phy_cmd_lxt971_startup,
978 .ack_int = phy_cmd_lxt971_ack_int,
979 .shutdown = phy_cmd_lxt971_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980};
981
982/* ------------------------------------------------------------------------- */
983/* The Quality Semiconductor QS6612 is used on the RPX CLLF */
984
985/* register definitions */
986
987#define MII_QS6612_MCR 17 /* Mode Control Register */
988#define MII_QS6612_FTR 27 /* Factory Test Register */
989#define MII_QS6612_MCO 28 /* Misc. Control Register */
990#define MII_QS6612_ISR 29 /* Interrupt Source Register */
991#define MII_QS6612_IMR 30 /* Interrupt Mask Register */
992#define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
993
994static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
995{
996 struct fec_enet_private *fep = netdev_priv(dev);
997 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +1000998 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001000 status = *s & ~(PHY_STAT_SPMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 switch((mii_reg >> 2) & 7) {
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001003 case 1: status |= PHY_STAT_10HDX; break;
1004 case 2: status |= PHY_STAT_100HDX; break;
1005 case 5: status |= PHY_STAT_10FDX; break;
1006 case 6: status |= PHY_STAT_100FDX; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001009 *s = status;
1010}
1011
1012static phy_cmd_t const phy_cmd_qs6612_config[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001013 /* The PHY powers up isolated on the RPX,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 * so send a command to allow operation.
1015 */
1016 { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
1017
1018 /* parse cr and anar to get some info */
1019 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1020 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1021 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001022 };
1023static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL },
1025 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1026 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001027 };
1028static phy_cmd_t const phy_cmd_qs6612_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* we need to read ISR, SR and ANER to acknowledge */
1030 { mk_mii_read(MII_QS6612_ISR), NULL },
1031 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1032 { mk_mii_read(MII_REG_ANER), NULL },
1033
1034 /* read pcr to get info */
1035 { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr },
1036 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001037 };
1038static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL },
1040 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001041 };
1042static phy_info_t const phy_info_qs6612 = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001043 .id = 0x00181440,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001044 .name = "QS6612",
1045 .config = phy_cmd_qs6612_config,
1046 .startup = phy_cmd_qs6612_startup,
1047 .ack_int = phy_cmd_qs6612_ack_int,
1048 .shutdown = phy_cmd_qs6612_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049};
1050
1051/* ------------------------------------------------------------------------- */
1052/* AMD AM79C874 phy */
1053
1054/* register definitions for the 874 */
1055
1056#define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
1057#define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
1058#define MII_AM79C874_DR 18 /* Diagnostic Register */
1059#define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
1060#define MII_AM79C874_MCR 21 /* ModeControl Register */
1061#define MII_AM79C874_DC 23 /* Disconnect Counter */
1062#define MII_AM79C874_REC 24 /* Recieve Error Counter */
1063
1064static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev)
1065{
1066 struct fec_enet_private *fep = netdev_priv(dev);
1067 volatile uint *s = &(fep->phy_status);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001068 uint status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001070 status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 if (mii_reg & 0x0080)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001073 status |= PHY_STAT_ANC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 if (mii_reg & 0x0400)
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001075 status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 else
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001077 status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
1078
1079 *s = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001082static phy_cmd_t const phy_cmd_am79c874_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1084 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1085 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1086 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001087 };
1088static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
1090 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001091 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001093 };
1094static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 /* find out the current status */
1096 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1097 { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr },
1098 /* we only need to read ISR to acknowledge */
1099 { mk_mii_read(MII_AM79C874_ICSR), NULL },
1100 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001101 };
1102static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL },
1104 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001105 };
1106static phy_info_t const phy_info_am79c874 = {
1107 .id = 0x00022561,
1108 .name = "AM79C874",
1109 .config = phy_cmd_am79c874_config,
1110 .startup = phy_cmd_am79c874_startup,
1111 .ack_int = phy_cmd_am79c874_ack_int,
1112 .shutdown = phy_cmd_am79c874_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113};
1114
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116/* ------------------------------------------------------------------------- */
1117/* Kendin KS8721BL phy */
1118
1119/* register definitions for the 8721 */
1120
1121#define MII_KS8721BL_RXERCR 21
1122#define MII_KS8721BL_ICSR 22
1123#define MII_KS8721BL_PHYCR 31
1124
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001125static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1127 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1128 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001129 };
1130static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
1132 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001133 { mk_mii_read(MII_REG_SR), mii_parse_sr },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001135 };
1136static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /* find out the current status */
1138 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1139 /* we only need to read ISR to acknowledge */
1140 { mk_mii_read(MII_KS8721BL_ICSR), NULL },
1141 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001142 };
1143static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL },
1145 { mk_mii_end, }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001146 };
1147static phy_info_t const phy_info_ks8721bl = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001148 .id = 0x00022161,
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001149 .name = "KS8721BL",
1150 .config = phy_cmd_ks8721bl_config,
1151 .startup = phy_cmd_ks8721bl_startup,
1152 .ack_int = phy_cmd_ks8721bl_ack_int,
1153 .shutdown = phy_cmd_ks8721bl_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154};
1155
1156/* ------------------------------------------------------------------------- */
Greg Ungerer562d2f82005-11-07 14:09:50 +10001157/* register definitions for the DP83848 */
1158
1159#define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
1160
1161static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
1162{
1163 struct fec_enet_private *fep = dev->priv;
1164 volatile uint *s = &(fep->phy_status);
1165
1166 *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
1167
1168 /* Link up */
1169 if (mii_reg & 0x0001) {
1170 fep->link = 1;
1171 *s |= PHY_STAT_LINK;
1172 } else
1173 fep->link = 0;
1174 /* Status of link */
1175 if (mii_reg & 0x0010) /* Autonegotioation complete */
1176 *s |= PHY_STAT_ANC;
1177 if (mii_reg & 0x0002) { /* 10MBps? */
1178 if (mii_reg & 0x0004) /* Full Duplex? */
1179 *s |= PHY_STAT_10FDX;
1180 else
1181 *s |= PHY_STAT_10HDX;
1182 } else { /* 100 Mbps? */
1183 if (mii_reg & 0x0004) /* Full Duplex? */
1184 *s |= PHY_STAT_100FDX;
1185 else
1186 *s |= PHY_STAT_100HDX;
1187 }
1188 if (mii_reg & 0x0008)
1189 *s |= PHY_STAT_FAULT;
1190}
1191
1192static phy_info_t phy_info_dp83848= {
1193 0x020005c9,
1194 "DP83848",
1195
1196 (const phy_cmd_t []) { /* config */
1197 { mk_mii_read(MII_REG_CR), mii_parse_cr },
1198 { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
1199 { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 },
1200 { mk_mii_end, }
1201 },
1202 (const phy_cmd_t []) { /* startup - enable interrupts */
1203 { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
1204 { mk_mii_read(MII_REG_SR), mii_parse_sr },
1205 { mk_mii_end, }
1206 },
1207 (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */
1208 { mk_mii_end, }
1209 },
1210 (const phy_cmd_t []) { /* shutdown */
1211 { mk_mii_end, }
1212 },
1213};
1214
1215/* ------------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001217static phy_info_t const * const phy_info[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 &phy_info_lxt970,
1219 &phy_info_lxt971,
1220 &phy_info_qs6612,
1221 &phy_info_am79c874,
1222 &phy_info_ks8721bl,
Greg Ungerer562d2f82005-11-07 14:09:50 +10001223 &phy_info_dp83848,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 NULL
1225};
1226
1227/* ------------------------------------------------------------------------- */
Matt Waddel6b265292006-06-27 13:10:56 +10001228#if !defined(CONFIG_M532x)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229#ifdef CONFIG_RPXCLASSIC
1230static void
1231mii_link_interrupt(void *dev_id);
1232#else
1233static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001234mii_link_interrupt(int irq, void * dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235#endif
Matt Waddel6b265292006-06-27 13:10:56 +10001236#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238#if defined(CONFIG_M5272)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239/*
1240 * Code specific to Coldfire 5272 setup.
1241 */
1242static void __inline__ fec_request_intrs(struct net_device *dev)
1243{
1244 volatile unsigned long *icrp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001245 static const struct idesc {
1246 char *name;
1247 unsigned short irq;
David Howells7d12e782006-10-05 14:55:46 +01001248 irq_handler_t handler;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001249 } *idp, id[] = {
1250 { "fec(RX)", 86, fec_enet_interrupt },
1251 { "fec(TX)", 87, fec_enet_interrupt },
1252 { "fec(OTHER)", 88, fec_enet_interrupt },
1253 { "fec(MII)", 66, mii_link_interrupt },
1254 { NULL },
1255 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
1257 /* Setup interrupt handlers. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001258 for (idp = id; idp->name; idp++) {
1259 if (request_irq(idp->irq, idp->handler, 0, idp->name, dev) != 0)
1260 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, idp->irq);
1261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 /* Unmask interrupt at ColdFire 5272 SIM */
1264 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3);
1265 *icrp = 0x00000ddd;
1266 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001267 *icrp = 0x0d000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1271{
1272 volatile fec_t *fecp;
1273
1274 fecp = fep->hwp;
1275 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1276 fecp->fec_x_cntrl = 0x00;
1277
1278 /*
1279 * Set MII speed to 2.5 MHz
1280 * See 5272 manual section 11.5.8: MSCR
1281 */
1282 fep->phy_speed = ((((MCF_CLK / 4) / (2500000 / 10)) + 5) / 10) * 2;
1283 fecp->fec_mii_speed = fep->phy_speed;
1284
1285 fec_restart(dev, 0);
1286}
1287
1288static void __inline__ fec_get_mac(struct net_device *dev)
1289{
1290 struct fec_enet_private *fep = netdev_priv(dev);
1291 volatile fec_t *fecp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001292 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 fecp = fep->hwp;
1295
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001296 if (FEC_FLASHMAC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 /*
1298 * Get MAC address from FLASH.
1299 * If it is all 1's or 0's, use the default.
1300 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001301 iap = (unsigned char *)FEC_FLASHMAC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1303 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1304 iap = fec_mac_default;
1305 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1306 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1307 iap = fec_mac_default;
1308 } else {
1309 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1310 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1311 iap = &tmpaddr[0];
1312 }
1313
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001314 memcpy(dev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 /* Adjust MAC if using default MAC address */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001317 if (iap == fec_mac_default)
1318 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
1321static void __inline__ fec_enable_phy_intr(void)
1322{
1323}
1324
1325static void __inline__ fec_disable_phy_intr(void)
1326{
1327 volatile unsigned long *icrp;
1328 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001329 *icrp = 0x08000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330}
1331
1332static void __inline__ fec_phy_ack_intr(void)
1333{
1334 volatile unsigned long *icrp;
1335 /* Acknowledge the interrupt */
1336 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
Greg Ungererf861d622007-07-30 16:29:16 +10001337 *icrp = 0x0d000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
1340static void __inline__ fec_localhw_setup(void)
1341{
1342}
1343
1344/*
1345 * Do not need to make region uncached on 5272.
1346 */
1347static void __inline__ fec_uncache(unsigned long addr)
1348{
1349}
1350
1351/* ------------------------------------------------------------------------- */
1352
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001353#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355/*
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001356 * Code specific to Coldfire 5230/5231/5232/5234/5235,
1357 * the 5270/5271/5274/5275 and 5280/5282 setups.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 */
1359static void __inline__ fec_request_intrs(struct net_device *dev)
1360{
1361 struct fec_enet_private *fep;
1362 int b;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001363 static const struct idesc {
1364 char *name;
1365 unsigned short irq;
1366 } *idp, id[] = {
1367 { "fec(TXF)", 23 },
1368 { "fec(TXB)", 24 },
1369 { "fec(TXFIFO)", 25 },
1370 { "fec(TXCR)", 26 },
1371 { "fec(RXF)", 27 },
1372 { "fec(RXB)", 28 },
1373 { "fec(MII)", 29 },
1374 { "fec(LC)", 30 },
1375 { "fec(HBERR)", 31 },
1376 { "fec(GRA)", 32 },
1377 { "fec(EBERR)", 33 },
1378 { "fec(BABT)", 34 },
1379 { "fec(BABR)", 35 },
1380 { NULL },
1381 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 fep = netdev_priv(dev);
1384 b = (fep->index) ? 128 : 64;
1385
1386 /* Setup interrupt handlers. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001387 for (idp = id; idp->name; idp++) {
1388 if (request_irq(b+idp->irq, fec_enet_interrupt, 0, idp->name, dev) != 0)
1389 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
1393 {
1394 volatile unsigned char *icrp;
1395 volatile unsigned long *imrp;
Willson Callan83901fc2006-06-27 13:13:44 +10001396 int i, ilip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 b = (fep->index) ? MCFICM_INTC1 : MCFICM_INTC0;
1399 icrp = (volatile unsigned char *) (MCF_IPSBAR + b +
1400 MCFINTC_ICR0);
Willson Callan83901fc2006-06-27 13:13:44 +10001401 for (i = 23, ilip = 0x28; (i < 36); i++)
1402 icrp[i] = ilip--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
1405 MCFINTC_IMRH);
1406 *imrp &= ~0x0000000f;
1407 imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
1408 MCFINTC_IMRL);
1409 *imrp &= ~0xff800001;
1410 }
1411
1412#if defined(CONFIG_M528x)
1413 /* Set up gpio outputs for MII lines */
1414 {
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001415 volatile u16 *gpio_paspar;
1416 volatile u8 *gpio_pehlpar;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001417
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001418 gpio_paspar = (volatile u16 *) (MCF_IPSBAR + 0x100056);
1419 gpio_pehlpar = (volatile u16 *) (MCF_IPSBAR + 0x100058);
1420 *gpio_paspar |= 0x0f00;
1421 *gpio_pehlpar = 0xc0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423#endif
Mike Cruseb8a94b32007-07-30 16:29:29 +10001424
1425#if defined(CONFIG_M527x)
1426 /* Set up gpio outputs for MII lines */
1427 {
1428 volatile u8 *gpio_par_fec;
1429 volatile u16 *gpio_par_feci2c;
1430
1431 gpio_par_feci2c = (volatile u16 *)(MCF_IPSBAR + 0x100082);
1432 /* Set up gpio outputs for FEC0 MII lines */
1433 gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100078);
1434
1435 *gpio_par_feci2c |= 0x0f00;
1436 *gpio_par_fec |= 0xc0;
1437
1438#if defined(CONFIG_FEC2)
1439 /* Set up gpio outputs for FEC1 MII lines */
1440 gpio_par_fec = (volatile u8 *)(MCF_IPSBAR + 0x100079);
1441
1442 *gpio_par_feci2c |= 0x00a0;
1443 *gpio_par_fec |= 0xc0;
1444#endif /* CONFIG_FEC2 */
1445 }
1446#endif /* CONFIG_M527x */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
1449static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1450{
1451 volatile fec_t *fecp;
1452
1453 fecp = fep->hwp;
1454 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1455 fecp->fec_x_cntrl = 0x00;
1456
1457 /*
1458 * Set MII speed to 2.5 MHz
1459 * See 5282 manual section 17.5.4.7: MSCR
1460 */
1461 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1462 fecp->fec_mii_speed = fep->phy_speed;
1463
1464 fec_restart(dev, 0);
1465}
1466
1467static void __inline__ fec_get_mac(struct net_device *dev)
1468{
1469 struct fec_enet_private *fep = netdev_priv(dev);
1470 volatile fec_t *fecp;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001471 unsigned char *iap, tmpaddr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 fecp = fep->hwp;
1474
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001475 if (FEC_FLASHMAC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 /*
1477 * Get MAC address from FLASH.
1478 * If it is all 1's or 0's, use the default.
1479 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001480 iap = FEC_FLASHMAC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1482 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1483 iap = fec_mac_default;
1484 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1485 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1486 iap = fec_mac_default;
1487 } else {
1488 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1489 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1490 iap = &tmpaddr[0];
1491 }
1492
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001493 memcpy(dev->dev_addr, iap, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 /* Adjust MAC if using default MAC address */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001496 if (iap == fec_mac_default)
1497 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
1500static void __inline__ fec_enable_phy_intr(void)
1501{
1502}
1503
1504static void __inline__ fec_disable_phy_intr(void)
1505{
1506}
1507
1508static void __inline__ fec_phy_ack_intr(void)
1509{
1510}
1511
1512static void __inline__ fec_localhw_setup(void)
1513{
1514}
1515
1516/*
1517 * Do not need to make region uncached on 5272.
1518 */
1519static void __inline__ fec_uncache(unsigned long addr)
1520{
1521}
1522
1523/* ------------------------------------------------------------------------- */
1524
Greg Ungerer562d2f82005-11-07 14:09:50 +10001525#elif defined(CONFIG_M520x)
1526
1527/*
1528 * Code specific to Coldfire 520x
1529 */
1530static void __inline__ fec_request_intrs(struct net_device *dev)
1531{
1532 struct fec_enet_private *fep;
1533 int b;
1534 static const struct idesc {
1535 char *name;
1536 unsigned short irq;
1537 } *idp, id[] = {
1538 { "fec(TXF)", 23 },
1539 { "fec(TXB)", 24 },
1540 { "fec(TXFIFO)", 25 },
1541 { "fec(TXCR)", 26 },
1542 { "fec(RXF)", 27 },
1543 { "fec(RXB)", 28 },
1544 { "fec(MII)", 29 },
1545 { "fec(LC)", 30 },
1546 { "fec(HBERR)", 31 },
1547 { "fec(GRA)", 32 },
1548 { "fec(EBERR)", 33 },
1549 { "fec(BABT)", 34 },
1550 { "fec(BABR)", 35 },
1551 { NULL },
1552 };
1553
1554 fep = netdev_priv(dev);
1555 b = 64 + 13;
1556
1557 /* Setup interrupt handlers. */
1558 for (idp = id; idp->name; idp++) {
1559 if (request_irq(b+idp->irq,fec_enet_interrupt,0,idp->name,dev)!=0)
1560 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
1561 }
1562
1563 /* Unmask interrupts at ColdFire interrupt controller */
1564 {
1565 volatile unsigned char *icrp;
1566 volatile unsigned long *imrp;
1567
1568 icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
1569 MCFINTC_ICR0);
1570 for (b = 36; (b < 49); b++)
1571 icrp[b] = 0x04;
1572 imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 +
1573 MCFINTC_IMRH);
1574 *imrp &= ~0x0001FFF0;
1575 }
1576 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FEC) |= 0xf0;
1577 *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C) |= 0x0f;
1578}
1579
1580static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1581{
1582 volatile fec_t *fecp;
1583
1584 fecp = fep->hwp;
1585 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1586 fecp->fec_x_cntrl = 0x00;
1587
1588 /*
1589 * Set MII speed to 2.5 MHz
1590 * See 5282 manual section 17.5.4.7: MSCR
1591 */
1592 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1593 fecp->fec_mii_speed = fep->phy_speed;
1594
1595 fec_restart(dev, 0);
1596}
1597
1598static void __inline__ fec_get_mac(struct net_device *dev)
1599{
1600 struct fec_enet_private *fep = netdev_priv(dev);
1601 volatile fec_t *fecp;
1602 unsigned char *iap, tmpaddr[ETH_ALEN];
1603
1604 fecp = fep->hwp;
1605
1606 if (FEC_FLASHMAC) {
1607 /*
1608 * Get MAC address from FLASH.
1609 * If it is all 1's or 0's, use the default.
1610 */
1611 iap = FEC_FLASHMAC;
1612 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1613 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1614 iap = fec_mac_default;
1615 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1616 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1617 iap = fec_mac_default;
1618 } else {
1619 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1620 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1621 iap = &tmpaddr[0];
1622 }
1623
1624 memcpy(dev->dev_addr, iap, ETH_ALEN);
1625
1626 /* Adjust MAC if using default MAC address */
1627 if (iap == fec_mac_default)
1628 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1629}
1630
1631static void __inline__ fec_enable_phy_intr(void)
1632{
1633}
1634
1635static void __inline__ fec_disable_phy_intr(void)
1636{
1637}
1638
1639static void __inline__ fec_phy_ack_intr(void)
1640{
1641}
1642
1643static void __inline__ fec_localhw_setup(void)
1644{
1645}
1646
1647static void __inline__ fec_uncache(unsigned long addr)
1648{
1649}
1650
1651/* ------------------------------------------------------------------------- */
1652
Matt Waddel6b265292006-06-27 13:10:56 +10001653#elif defined(CONFIG_M532x)
1654/*
1655 * Code specific for M532x
1656 */
1657static void __inline__ fec_request_intrs(struct net_device *dev)
1658{
1659 struct fec_enet_private *fep;
1660 int b;
1661 static const struct idesc {
1662 char *name;
1663 unsigned short irq;
1664 } *idp, id[] = {
1665 { "fec(TXF)", 36 },
1666 { "fec(TXB)", 37 },
1667 { "fec(TXFIFO)", 38 },
1668 { "fec(TXCR)", 39 },
1669 { "fec(RXF)", 40 },
1670 { "fec(RXB)", 41 },
1671 { "fec(MII)", 42 },
1672 { "fec(LC)", 43 },
1673 { "fec(HBERR)", 44 },
1674 { "fec(GRA)", 45 },
1675 { "fec(EBERR)", 46 },
1676 { "fec(BABT)", 47 },
1677 { "fec(BABR)", 48 },
1678 { NULL },
1679 };
1680
1681 fep = netdev_priv(dev);
1682 b = (fep->index) ? 128 : 64;
1683
1684 /* Setup interrupt handlers. */
1685 for (idp = id; idp->name; idp++) {
1686 if (request_irq(b+idp->irq,fec_enet_interrupt,0,idp->name,dev)!=0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001687 printk("FEC: Could not allocate %s IRQ(%d)!\n",
Matt Waddel6b265292006-06-27 13:10:56 +10001688 idp->name, b+idp->irq);
1689 }
1690
1691 /* Unmask interrupts */
1692 MCF_INTC0_ICR36 = 0x2;
1693 MCF_INTC0_ICR37 = 0x2;
1694 MCF_INTC0_ICR38 = 0x2;
1695 MCF_INTC0_ICR39 = 0x2;
1696 MCF_INTC0_ICR40 = 0x2;
1697 MCF_INTC0_ICR41 = 0x2;
1698 MCF_INTC0_ICR42 = 0x2;
1699 MCF_INTC0_ICR43 = 0x2;
1700 MCF_INTC0_ICR44 = 0x2;
1701 MCF_INTC0_ICR45 = 0x2;
1702 MCF_INTC0_ICR46 = 0x2;
1703 MCF_INTC0_ICR47 = 0x2;
1704 MCF_INTC0_ICR48 = 0x2;
1705
1706 MCF_INTC0_IMRH &= ~(
1707 MCF_INTC_IMRH_INT_MASK36 |
1708 MCF_INTC_IMRH_INT_MASK37 |
1709 MCF_INTC_IMRH_INT_MASK38 |
1710 MCF_INTC_IMRH_INT_MASK39 |
1711 MCF_INTC_IMRH_INT_MASK40 |
1712 MCF_INTC_IMRH_INT_MASK41 |
1713 MCF_INTC_IMRH_INT_MASK42 |
1714 MCF_INTC_IMRH_INT_MASK43 |
1715 MCF_INTC_IMRH_INT_MASK44 |
1716 MCF_INTC_IMRH_INT_MASK45 |
1717 MCF_INTC_IMRH_INT_MASK46 |
1718 MCF_INTC_IMRH_INT_MASK47 |
1719 MCF_INTC_IMRH_INT_MASK48 );
1720
1721 /* Set up gpio outputs for MII lines */
1722 MCF_GPIO_PAR_FECI2C |= (0 |
1723 MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
1724 MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO);
1725 MCF_GPIO_PAR_FEC = (0 |
1726 MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC |
1727 MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC);
1728}
1729
1730static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1731{
1732 volatile fec_t *fecp;
1733
1734 fecp = fep->hwp;
1735 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
1736 fecp->fec_x_cntrl = 0x00;
1737
1738 /*
1739 * Set MII speed to 2.5 MHz
1740 */
1741 fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
1742 fecp->fec_mii_speed = fep->phy_speed;
1743
1744 fec_restart(dev, 0);
1745}
1746
1747static void __inline__ fec_get_mac(struct net_device *dev)
1748{
1749 struct fec_enet_private *fep = netdev_priv(dev);
1750 volatile fec_t *fecp;
1751 unsigned char *iap, tmpaddr[ETH_ALEN];
1752
1753 fecp = fep->hwp;
1754
1755 if (FEC_FLASHMAC) {
1756 /*
1757 * Get MAC address from FLASH.
1758 * If it is all 1's or 0's, use the default.
1759 */
1760 iap = FEC_FLASHMAC;
1761 if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
1762 (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
1763 iap = fec_mac_default;
1764 if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
1765 (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
1766 iap = fec_mac_default;
1767 } else {
1768 *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
1769 *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
1770 iap = &tmpaddr[0];
1771 }
1772
1773 memcpy(dev->dev_addr, iap, ETH_ALEN);
1774
1775 /* Adjust MAC if using default MAC address */
1776 if (iap == fec_mac_default)
1777 dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
1778}
1779
1780static void __inline__ fec_enable_phy_intr(void)
1781{
1782}
1783
1784static void __inline__ fec_disable_phy_intr(void)
1785{
1786}
1787
1788static void __inline__ fec_phy_ack_intr(void)
1789{
1790}
1791
1792static void __inline__ fec_localhw_setup(void)
1793{
1794}
1795
1796/*
1797 * Do not need to make region uncached on 532x.
1798 */
1799static void __inline__ fec_uncache(unsigned long addr)
1800{
1801}
1802
1803/* ------------------------------------------------------------------------- */
1804
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806#else
1807
1808/*
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001809 * Code specific to the MPC860T setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 */
1811static void __inline__ fec_request_intrs(struct net_device *dev)
1812{
1813 volatile immap_t *immap;
1814
1815 immap = (immap_t *)IMAP_ADDR; /* pointer to internal registers */
1816
1817 if (request_8xxirq(FEC_INTERRUPT, fec_enet_interrupt, 0, "fec", dev) != 0)
1818 panic("Could not allocate FEC IRQ!");
1819
1820#ifdef CONFIG_RPXCLASSIC
1821 /* Make Port C, bit 15 an input that causes interrupts.
1822 */
1823 immap->im_ioport.iop_pcpar &= ~0x0001;
1824 immap->im_ioport.iop_pcdir &= ~0x0001;
1825 immap->im_ioport.iop_pcso &= ~0x0001;
1826 immap->im_ioport.iop_pcint |= 0x0001;
1827 cpm_install_handler(CPMVEC_PIO_PC15, mii_link_interrupt, dev);
1828
1829 /* Make LEDS reflect Link status.
1830 */
1831 *((uint *) RPX_CSR_ADDR) &= ~BCSR2_FETHLEDMODE;
1832#endif
1833#ifdef CONFIG_FADS
1834 if (request_8xxirq(SIU_IRQ2, mii_link_interrupt, 0, "mii", dev) != 0)
1835 panic("Could not allocate MII IRQ!");
1836#endif
1837}
1838
1839static void __inline__ fec_get_mac(struct net_device *dev)
1840{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 bd_t *bd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 bd = (bd_t *)__res;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001844 memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846#ifdef CONFIG_RPXCLASSIC
1847 /* The Embedded Planet boards have only one MAC address in
1848 * the EEPROM, but can have two Ethernet ports. For the
1849 * FEC port, we create another address by setting one of
1850 * the address bits above something that would have (up to
1851 * now) been allocated.
1852 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001853 dev->dev_adrd[3] |= 0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855}
1856
1857static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
1858{
1859 extern uint _get_IMMR(void);
1860 volatile immap_t *immap;
1861 volatile fec_t *fecp;
1862
1863 fecp = fep->hwp;
1864 immap = (immap_t *)IMAP_ADDR; /* pointer to internal registers */
1865
1866 /* Configure all of port D for MII.
1867 */
1868 immap->im_ioport.iop_pdpar = 0x1fff;
1869
1870 /* Bits moved from Rev. D onward.
1871 */
1872 if ((_get_IMMR() & 0xffff) < 0x0501)
1873 immap->im_ioport.iop_pddir = 0x1c58; /* Pre rev. D */
1874 else
1875 immap->im_ioport.iop_pddir = 0x1fff; /* Rev. D and later */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001876
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 /* Set MII speed to 2.5 MHz
1878 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001879 fecp->fec_mii_speed = fep->phy_speed =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 ((bd->bi_busfreq * 1000000) / 2500000) & 0x7e;
1881}
1882
1883static void __inline__ fec_enable_phy_intr(void)
1884{
1885 volatile fec_t *fecp;
1886
1887 fecp = fep->hwp;
1888
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001889 /* Enable MII command finished interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 */
1891 fecp->fec_ivec = (FEC_INTERRUPT/2) << 29;
1892}
1893
1894static void __inline__ fec_disable_phy_intr(void)
1895{
1896}
1897
1898static void __inline__ fec_phy_ack_intr(void)
1899{
1900}
1901
1902static void __inline__ fec_localhw_setup(void)
1903{
1904 volatile fec_t *fecp;
1905
1906 fecp = fep->hwp;
1907 fecp->fec_r_hash = PKT_MAXBUF_SIZE;
1908 /* Enable big endian and don't care about SDMA FC.
1909 */
1910 fecp->fec_fun_code = 0x78000000;
1911}
1912
1913static void __inline__ fec_uncache(unsigned long addr)
1914{
1915 pte_t *pte;
1916 pte = va_to_pte(mem_addr);
1917 pte_val(*pte) |= _PAGE_NO_CACHE;
1918 flush_tlb_page(init_mm.mmap, mem_addr);
1919}
1920
1921#endif
1922
1923/* ------------------------------------------------------------------------- */
1924
1925static void mii_display_status(struct net_device *dev)
1926{
1927 struct fec_enet_private *fep = netdev_priv(dev);
1928 volatile uint *s = &(fep->phy_status);
1929
1930 if (!fep->link && !fep->old_link) {
1931 /* Link is still down - don't print anything */
1932 return;
1933 }
1934
1935 printk("%s: status: ", dev->name);
1936
1937 if (!fep->link) {
1938 printk("link down");
1939 } else {
1940 printk("link up");
1941
1942 switch(*s & PHY_STAT_SPMASK) {
1943 case PHY_STAT_100FDX: printk(", 100MBit Full Duplex"); break;
1944 case PHY_STAT_100HDX: printk(", 100MBit Half Duplex"); break;
1945 case PHY_STAT_10FDX: printk(", 10MBit Full Duplex"); break;
1946 case PHY_STAT_10HDX: printk(", 10MBit Half Duplex"); break;
1947 default:
1948 printk(", Unknown speed/duplex");
1949 }
1950
1951 if (*s & PHY_STAT_ANC)
1952 printk(", auto-negotiation complete");
1953 }
1954
1955 if (*s & PHY_STAT_FAULT)
1956 printk(", remote fault");
1957
1958 printk(".\n");
1959}
1960
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001961static void mii_display_config(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001963 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
1964 struct net_device *dev = fep->netdev;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001965 uint status = fep->phy_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
1967 /*
1968 ** When we get here, phy_task is already removed from
1969 ** the workqueue. It is thus safe to allow to reuse it.
1970 */
1971 fep->mii_phy_task_queued = 0;
1972 printk("%s: config: auto-negotiation ", dev->name);
1973
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001974 if (status & PHY_CONF_ANE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 printk("on");
1976 else
1977 printk("off");
1978
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001979 if (status & PHY_CONF_100FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 printk(", 100FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001981 if (status & PHY_CONF_100HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 printk(", 100HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001983 if (status & PHY_CONF_10FDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 printk(", 10FDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001985 if (status & PHY_CONF_10HDX)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 printk(", 10HDX");
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001987 if (!(status & PHY_CONF_SPMASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 printk(", No speed/duplex selected?");
1989
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10001990 if (status & PHY_CONF_LOOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 printk(", loopback enabled");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001992
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 printk(".\n");
1994
1995 fep->sequence_done = 1;
1996}
1997
Greg Ungerercb84d6e2007-07-30 16:29:09 +10001998static void mii_relink(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002000 struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
2001 struct net_device *dev = fep->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 int duplex;
2003
2004 /*
2005 ** When we get here, phy_task is already removed from
2006 ** the workqueue. It is thus safe to allow to reuse it.
2007 */
2008 fep->mii_phy_task_queued = 0;
2009 fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0;
2010 mii_display_status(dev);
2011 fep->old_link = fep->link;
2012
2013 if (fep->link) {
2014 duplex = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002015 if (fep->phy_status
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 & (PHY_STAT_100FDX | PHY_STAT_10FDX))
2017 duplex = 1;
2018 fec_restart(dev, duplex);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10002019 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 fec_stop(dev);
2021
2022#if 0
2023 enable_irq(fep->mii_irq);
2024#endif
2025
2026}
2027
2028/* mii_queue_relink is called in interrupt context from mii_link_interrupt */
2029static void mii_queue_relink(uint mii_reg, struct net_device *dev)
2030{
2031 struct fec_enet_private *fep = netdev_priv(dev);
2032
2033 /*
2034 ** We cannot queue phy_task twice in the workqueue. It
2035 ** would cause an endless loop in the workqueue.
2036 ** Fortunately, if the last mii_relink entry has not yet been
2037 ** executed now, it will do the job for the current interrupt,
2038 ** which is just what we want.
2039 */
2040 if (fep->mii_phy_task_queued)
2041 return;
2042
2043 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002044 INIT_WORK(&fep->phy_task, mii_relink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 schedule_work(&fep->phy_task);
2046}
2047
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002048/* mii_queue_config is called in interrupt context from fec_enet_mii */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049static void mii_queue_config(uint mii_reg, struct net_device *dev)
2050{
2051 struct fec_enet_private *fep = netdev_priv(dev);
2052
2053 if (fep->mii_phy_task_queued)
2054 return;
2055
2056 fep->mii_phy_task_queued = 1;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002057 INIT_WORK(&fep->phy_task, mii_display_config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 schedule_work(&fep->phy_task);
2059}
2060
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002061phy_cmd_t const phy_cmd_relink[] = {
2062 { mk_mii_read(MII_REG_CR), mii_queue_relink },
2063 { mk_mii_end, }
2064 };
2065phy_cmd_t const phy_cmd_config[] = {
2066 { mk_mii_read(MII_REG_CR), mii_queue_config },
2067 { mk_mii_end, }
2068 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070/* Read remainder of PHY ID.
2071*/
2072static void
2073mii_discover_phy3(uint mii_reg, struct net_device *dev)
2074{
2075 struct fec_enet_private *fep;
2076 int i;
2077
2078 fep = netdev_priv(dev);
2079 fep->phy_id |= (mii_reg & 0xffff);
2080 printk("fec: PHY @ 0x%x, ID 0x%08x", fep->phy_addr, fep->phy_id);
2081
2082 for(i = 0; phy_info[i]; i++) {
2083 if(phy_info[i]->id == (fep->phy_id >> 4))
2084 break;
2085 }
2086
2087 if (phy_info[i])
2088 printk(" -- %s\n", phy_info[i]->name);
2089 else
2090 printk(" -- unknown PHY!\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 fep->phy = phy_info[i];
2093 fep->phy_id_done = 1;
2094}
2095
2096/* Scan all of the MII PHY addresses looking for someone to respond
2097 * with a valid ID. This usually happens quickly.
2098 */
2099static void
2100mii_discover_phy(uint mii_reg, struct net_device *dev)
2101{
2102 struct fec_enet_private *fep;
2103 volatile fec_t *fecp;
2104 uint phytype;
2105
2106 fep = netdev_priv(dev);
2107 fecp = fep->hwp;
2108
2109 if (fep->phy_addr < 32) {
2110 if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 /* Got first part of ID, now get remainder.
2113 */
2114 fep->phy_id = phytype << 16;
2115 mii_queue(dev, mk_mii_read(MII_REG_PHYIR2),
2116 mii_discover_phy3);
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10002117 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 fep->phy_addr++;
2119 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1),
2120 mii_discover_phy);
2121 }
2122 } else {
2123 printk("FEC: No PHY device found.\n");
2124 /* Disable external MII interface */
2125 fecp->fec_mii_speed = fep->phy_speed = 0;
2126 fec_disable_phy_intr();
2127 }
2128}
2129
2130/* This interrupt occurs when the PHY detects a link change.
2131*/
2132#ifdef CONFIG_RPXCLASSIC
2133static void
2134mii_link_interrupt(void *dev_id)
2135#else
2136static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01002137mii_link_interrupt(int irq, void * dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138#endif
2139{
2140 struct net_device *dev = dev_id;
2141 struct fec_enet_private *fep = netdev_priv(dev);
2142
2143 fec_phy_ack_intr();
2144
2145#if 0
2146 disable_irq(fep->mii_irq); /* disable now, enable later */
2147#endif
2148
2149 mii_do_cmd(dev, fep->phy->ack_int);
2150 mii_do_cmd(dev, phy_cmd_relink); /* restart and display status */
2151
2152 return IRQ_HANDLED;
2153}
2154
2155static int
2156fec_enet_open(struct net_device *dev)
2157{
2158 struct fec_enet_private *fep = netdev_priv(dev);
2159
2160 /* I should reset the ring buffers here, but I don't yet know
2161 * a simple way to do that.
2162 */
2163 fec_set_mac_address(dev);
2164
2165 fep->sequence_done = 0;
2166 fep->link = 0;
2167
2168 if (fep->phy) {
2169 mii_do_cmd(dev, fep->phy->ack_int);
2170 mii_do_cmd(dev, fep->phy->config);
2171 mii_do_cmd(dev, phy_cmd_config); /* display configuration */
2172
Matt Waddel6b265292006-06-27 13:10:56 +10002173 /* Poll until the PHY tells us its configuration
2174 * (not link state).
2175 * Request is initiated by mii_do_cmd above, but answer
2176 * comes by interrupt.
2177 * This should take about 25 usec per register at 2.5 MHz,
2178 * and we read approximately 5 registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 */
2180 while(!fep->sequence_done)
2181 schedule();
2182
2183 mii_do_cmd(dev, fep->phy->startup);
2184
2185 /* Set the initial link state to true. A lot of hardware
2186 * based on this device does not implement a PHY interrupt,
2187 * so we are never notified of link change.
2188 */
2189 fep->link = 1;
2190 } else {
2191 fep->link = 1; /* lets just try it and see */
2192 /* no phy, go full duplex, it's most likely a hub chip */
2193 fec_restart(dev, 1);
2194 }
2195
2196 netif_start_queue(dev);
2197 fep->opened = 1;
2198 return 0; /* Success */
2199}
2200
2201static int
2202fec_enet_close(struct net_device *dev)
2203{
2204 struct fec_enet_private *fep = netdev_priv(dev);
2205
2206 /* Don't know what to do yet.
2207 */
2208 fep->opened = 0;
2209 netif_stop_queue(dev);
2210 fec_stop(dev);
2211
2212 return 0;
2213}
2214
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215/* Set or clear the multicast filter for this adaptor.
2216 * Skeleton taken from sunlance driver.
2217 * The CPM Ethernet implementation allows Multicast as well as individual
2218 * MAC address filtering. Some of the drivers check to make sure it is
2219 * a group multicast address, and discard those that are not. I guess I
2220 * will do the same for now, but just remove the test if you want
2221 * individual filtering as well (do the upper net layers want or support
2222 * this kind of feature?).
2223 */
2224
2225#define HASH_BITS 6 /* #bits in hash */
2226#define CRC32_POLY 0xEDB88320
2227
2228static void set_multicast_list(struct net_device *dev)
2229{
2230 struct fec_enet_private *fep;
2231 volatile fec_t *ep;
2232 struct dev_mc_list *dmi;
2233 unsigned int i, j, bit, data, crc;
2234 unsigned char hash;
2235
2236 fep = netdev_priv(dev);
2237 ep = fep->hwp;
2238
2239 if (dev->flags&IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 ep->fec_r_cntrl |= 0x0008;
2241 } else {
2242
2243 ep->fec_r_cntrl &= ~0x0008;
2244
2245 if (dev->flags & IFF_ALLMULTI) {
2246 /* Catch all multicast addresses, so set the
2247 * filter to all 1's.
2248 */
2249 ep->fec_hash_table_high = 0xffffffff;
2250 ep->fec_hash_table_low = 0xffffffff;
2251 } else {
2252 /* Clear filter and add the addresses in hash register.
2253 */
2254 ep->fec_hash_table_high = 0;
2255 ep->fec_hash_table_low = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 dmi = dev->mc_list;
2258
2259 for (j = 0; j < dev->mc_count; j++, dmi = dmi->next)
2260 {
2261 /* Only support group multicast for now.
2262 */
2263 if (!(dmi->dmi_addr[0] & 1))
2264 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 /* calculate crc32 value of mac address
2267 */
2268 crc = 0xffffffff;
2269
2270 for (i = 0; i < dmi->dmi_addrlen; i++)
2271 {
2272 data = dmi->dmi_addr[i];
2273 for (bit = 0; bit < 8; bit++, data >>= 1)
2274 {
2275 crc = (crc >> 1) ^
2276 (((crc ^ data) & 1) ? CRC32_POLY : 0);
2277 }
2278 }
2279
2280 /* only upper 6 bits (HASH_BITS) are used
2281 which point to specific bit in he hash registers
2282 */
2283 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (hash > 31)
2286 ep->fec_hash_table_high |= 1 << (hash - 32);
2287 else
2288 ep->fec_hash_table_low |= 1 << hash;
2289 }
2290 }
2291 }
2292}
2293
2294/* Set a MAC change in hardware.
2295 */
2296static void
2297fec_set_mac_address(struct net_device *dev)
2298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 volatile fec_t *fecp;
2300
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002301 fecp = ((struct fec_enet_private *)netdev_priv(dev))->hwp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
2303 /* Set station address. */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002304 fecp->fec_addr_low = dev->dev_addr[3] | (dev->dev_addr[2] << 8) |
2305 (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24);
2306 fecp->fec_addr_high = (dev->dev_addr[5] << 16) |
2307 (dev->dev_addr[4] << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309}
2310
2311/* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
2312 */
2313 /*
2314 * XXX: We need to clean up on failure exits here.
2315 */
2316int __init fec_enet_init(struct net_device *dev)
2317{
2318 struct fec_enet_private *fep = netdev_priv(dev);
2319 unsigned long mem_addr;
2320 volatile cbd_t *bdp;
2321 cbd_t *cbd_base;
2322 volatile fec_t *fecp;
2323 int i, j;
2324 static int index = 0;
2325
2326 /* Only allow us to be probed once. */
2327 if (index >= FEC_MAX_PORTS)
2328 return -ENXIO;
2329
Greg Ungerer562d2f82005-11-07 14:09:50 +10002330 /* Allocate memory for buffer descriptors.
2331 */
2332 mem_addr = __get_free_page(GFP_KERNEL);
2333 if (mem_addr == 0) {
2334 printk("FEC: allocate descriptor memory failed?\n");
2335 return -ENOMEM;
2336 }
2337
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 /* Create an Ethernet device instance.
2339 */
2340 fecp = (volatile fec_t *) fec_hw[index];
2341
2342 fep->index = index;
2343 fep->hwp = fecp;
Greg Ungerercb84d6e2007-07-30 16:29:09 +10002344 fep->netdev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 /* Whack a reset. We should wait for this.
2347 */
2348 fecp->fec_ecntrl = 1;
2349 udelay(10);
2350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 /* Set the Ethernet address. If using multiple Enets on the 8xx,
2352 * this needs some work to get unique addresses.
2353 *
2354 * This is our default MAC address unless the user changes
2355 * it via eth_mac_addr (our dev->set_mac_addr handler).
2356 */
2357 fec_get_mac(dev);
2358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 cbd_base = (cbd_t *)mem_addr;
2360 /* XXX: missing check for allocation failure */
2361
2362 fec_uncache(mem_addr);
2363
2364 /* Set receive and transmit descriptor base.
2365 */
2366 fep->rx_bd_base = cbd_base;
2367 fep->tx_bd_base = cbd_base + RX_RING_SIZE;
2368
2369 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
2370 fep->cur_rx = fep->rx_bd_base;
2371
2372 fep->skb_cur = fep->skb_dirty = 0;
2373
2374 /* Initialize the receive buffer descriptors.
2375 */
2376 bdp = fep->rx_bd_base;
2377 for (i=0; i<FEC_ENET_RX_PAGES; i++) {
2378
2379 /* Allocate a page.
2380 */
2381 mem_addr = __get_free_page(GFP_KERNEL);
2382 /* XXX: missing check for allocation failure */
2383
2384 fec_uncache(mem_addr);
2385
2386 /* Initialize the BD for every fragment in the page.
2387 */
2388 for (j=0; j<FEC_ENET_RX_FRPPG; j++) {
2389 bdp->cbd_sc = BD_ENET_RX_EMPTY;
2390 bdp->cbd_bufaddr = __pa(mem_addr);
2391 mem_addr += FEC_ENET_RX_FRSIZE;
2392 bdp++;
2393 }
2394 }
2395
2396 /* Set the last buffer to wrap.
2397 */
2398 bdp--;
2399 bdp->cbd_sc |= BD_SC_WRAP;
2400
2401 /* ...and the same for transmmit.
2402 */
2403 bdp = fep->tx_bd_base;
2404 for (i=0, j=FEC_ENET_TX_FRPPG; i<TX_RING_SIZE; i++) {
2405 if (j >= FEC_ENET_TX_FRPPG) {
2406 mem_addr = __get_free_page(GFP_KERNEL);
2407 j = 1;
2408 } else {
2409 mem_addr += FEC_ENET_TX_FRSIZE;
2410 j++;
2411 }
2412 fep->tx_bounce[i] = (unsigned char *) mem_addr;
2413
2414 /* Initialize the BD for every fragment in the page.
2415 */
2416 bdp->cbd_sc = 0;
2417 bdp->cbd_bufaddr = 0;
2418 bdp++;
2419 }
2420
2421 /* Set the last buffer to wrap.
2422 */
2423 bdp--;
2424 bdp->cbd_sc |= BD_SC_WRAP;
2425
2426 /* Set receive and transmit descriptor base.
2427 */
2428 fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
2429 fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
2430
2431 /* Install our interrupt handlers. This varies depending on
2432 * the architecture.
2433 */
2434 fec_request_intrs(dev);
2435
Greg Ungerer562d2f82005-11-07 14:09:50 +10002436 fecp->fec_hash_table_high = 0;
2437 fecp->fec_hash_table_low = 0;
2438 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2439 fecp->fec_ecntrl = 2;
Matt Waddel6b265292006-06-27 13:10:56 +10002440 fecp->fec_r_des_active = 0;
Greg Ungerer562d2f82005-11-07 14:09:50 +10002441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 dev->base_addr = (unsigned long)fecp;
2443
2444 /* The FEC Ethernet specific entries in the device structure. */
2445 dev->open = fec_enet_open;
2446 dev->hard_start_xmit = fec_enet_start_xmit;
2447 dev->tx_timeout = fec_timeout;
2448 dev->watchdog_timeo = TX_TIMEOUT;
2449 dev->stop = fec_enet_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 dev->set_multicast_list = set_multicast_list;
2451
2452 for (i=0; i<NMII-1; i++)
2453 mii_cmds[i].mii_next = &mii_cmds[i+1];
2454 mii_free = mii_cmds;
2455
2456 /* setup MII interface */
2457 fec_set_mii(dev, fep);
2458
Matt Waddel6b265292006-06-27 13:10:56 +10002459 /* Clear and enable interrupts */
2460 fecp->fec_ievent = 0xffc00000;
2461 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
2462 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2463
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 /* Queue up command to detect the PHY and initialize the
2465 * remainder of the interface.
2466 */
2467 fep->phy_id_done = 0;
2468 fep->phy_addr = 0;
2469 mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
2470
2471 index++;
2472 return 0;
2473}
2474
2475/* This function is called to start or restart the FEC during a link
2476 * change. This only happens when switching between half and full
2477 * duplex.
2478 */
2479static void
2480fec_restart(struct net_device *dev, int duplex)
2481{
2482 struct fec_enet_private *fep;
2483 volatile cbd_t *bdp;
2484 volatile fec_t *fecp;
2485 int i;
2486
2487 fep = netdev_priv(dev);
2488 fecp = fep->hwp;
2489
2490 /* Whack a reset. We should wait for this.
2491 */
2492 fecp->fec_ecntrl = 1;
2493 udelay(10);
2494
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 /* Clear any outstanding interrupt.
2496 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002497 fecp->fec_ievent = 0xffc00000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 fec_enable_phy_intr();
2499
2500 /* Set station address.
2501 */
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002502 fec_set_mac_address(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
2504 /* Reset all multicast.
2505 */
2506 fecp->fec_hash_table_high = 0;
2507 fecp->fec_hash_table_low = 0;
2508
2509 /* Set maximum receive buffer size.
2510 */
2511 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2512
2513 fec_localhw_setup();
2514
2515 /* Set receive and transmit descriptor base.
2516 */
2517 fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
2518 fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
2519
2520 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
2521 fep->cur_rx = fep->rx_bd_base;
2522
2523 /* Reset SKB transmit buffers.
2524 */
2525 fep->skb_cur = fep->skb_dirty = 0;
2526 for (i=0; i<=TX_RING_MOD_MASK; i++) {
2527 if (fep->tx_skbuff[i] != NULL) {
2528 dev_kfree_skb_any(fep->tx_skbuff[i]);
2529 fep->tx_skbuff[i] = NULL;
2530 }
2531 }
2532
2533 /* Initialize the receive buffer descriptors.
2534 */
2535 bdp = fep->rx_bd_base;
2536 for (i=0; i<RX_RING_SIZE; i++) {
2537
2538 /* Initialize the BD for every fragment in the page.
2539 */
2540 bdp->cbd_sc = BD_ENET_RX_EMPTY;
2541 bdp++;
2542 }
2543
2544 /* Set the last buffer to wrap.
2545 */
2546 bdp--;
2547 bdp->cbd_sc |= BD_SC_WRAP;
2548
2549 /* ...and the same for transmmit.
2550 */
2551 bdp = fep->tx_bd_base;
2552 for (i=0; i<TX_RING_SIZE; i++) {
2553
2554 /* Initialize the BD for every fragment in the page.
2555 */
2556 bdp->cbd_sc = 0;
2557 bdp->cbd_bufaddr = 0;
2558 bdp++;
2559 }
2560
2561 /* Set the last buffer to wrap.
2562 */
2563 bdp--;
2564 bdp->cbd_sc |= BD_SC_WRAP;
2565
2566 /* Enable MII mode.
2567 */
2568 if (duplex) {
2569 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;/* MII enable */
2570 fecp->fec_x_cntrl = 0x04; /* FD enable */
Philippe De Muyterf909b1e2007-10-23 14:37:54 +10002571 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 /* MII enable|No Rcv on Xmit */
2573 fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x06;
2574 fecp->fec_x_cntrl = 0x00;
2575 }
2576 fep->full_duplex = duplex;
2577
2578 /* Set MII speed.
2579 */
2580 fecp->fec_mii_speed = fep->phy_speed;
2581
2582 /* And last, enable the transmit and receive processing.
2583 */
2584 fecp->fec_ecntrl = 2;
Matt Waddel6b265292006-06-27 13:10:56 +10002585 fecp->fec_r_des_active = 0;
2586
2587 /* Enable interrupts we wish to service.
2588 */
2589 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
2590 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591}
2592
2593static void
2594fec_stop(struct net_device *dev)
2595{
2596 volatile fec_t *fecp;
2597 struct fec_enet_private *fep;
2598
2599 fep = netdev_priv(dev);
2600 fecp = fep->hwp;
2601
Philippe De Muyter677177c2006-06-27 13:05:33 +10002602 /*
2603 ** We cannot expect a graceful transmit stop without link !!!
2604 */
2605 if (fep->link)
2606 {
2607 fecp->fec_x_cntrl = 0x01; /* Graceful transmit stop */
2608 udelay(10);
2609 if (!(fecp->fec_ievent & FEC_ENET_GRA))
2610 printk("fec_stop : Graceful transmit stop did not complete !\n");
2611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 /* Whack a reset. We should wait for this.
2614 */
2615 fecp->fec_ecntrl = 1;
2616 udelay(10);
2617
2618 /* Clear outstanding MII command interrupts.
2619 */
2620 fecp->fec_ievent = FEC_ENET_MII;
2621 fec_enable_phy_intr();
2622
2623 fecp->fec_imask = FEC_ENET_MII;
2624 fecp->fec_mii_speed = fep->phy_speed;
2625}
2626
2627static int __init fec_enet_module_init(void)
2628{
2629 struct net_device *dev;
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002630 int i, j, err;
Joe Perches0795af52007-10-03 17:59:30 -07002631 DECLARE_MAC_BUF(mac);
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002632
2633 printk("FEC ENET Version 0.2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
2635 for (i = 0; (i < FEC_MAX_PORTS); i++) {
2636 dev = alloc_etherdev(sizeof(struct fec_enet_private));
2637 if (!dev)
2638 return -ENOMEM;
2639 err = fec_enet_init(dev);
2640 if (err) {
2641 free_netdev(dev);
2642 continue;
2643 }
2644 if (register_netdev(dev) != 0) {
2645 /* XXX: missing cleanup here */
2646 free_netdev(dev);
2647 return -EIO;
2648 }
Greg Ungerer7dd6a2a2005-09-12 11:18:10 +10002649
Joe Perches0795af52007-10-03 17:59:30 -07002650 printk("%s: ethernet %s\n",
2651 dev->name, print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 }
2653 return 0;
2654}
2655
2656module_init(fec_enet_module_init);
2657
2658MODULE_LICENSE("GPL");