2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
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.
11 * Right now, I am very wasteful with the buffers. I allocate memory
12 * 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
18 * Much better multiple PHY support by Magnus Damm.
19 * Copyright (c) 2000 Ericsson Radio Systems AB.
21 * Support for FEC controller of ColdFire/5270/5271/5272/5274/5275/5280/5282.
22 * Copyright (c) 2001-2004 Greg Ungerer (gerg@snapgear.com)
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/string.h>
29 #include <linux/ptrace.h>
30 #include <linux/errno.h>
31 #include <linux/ioport.h>
32 #include <linux/slab.h>
33 #include <linux/interrupt.h>
34 #include <linux/pci.h>
35 #include <linux/init.h>
36 #include <linux/delay.h>
37 #include <linux/netdevice.h>
38 #include <linux/etherdevice.h>
39 #include <linux/skbuff.h>
40 #include <linux/spinlock.h>
41 #include <linux/workqueue.h>
44 #include <asm/bitops.h>
45 #include <asm/uaccess.h>
47 #include <asm/pgtable.h>
49 #if defined(CONFIG_M527x) || defined(CONFIG_M5272) || defined(CONFIG_M528x)
50 #include <asm/coldfire.h>
51 #include <asm/mcfsim.h>
54 #include <asm/8xx_immap.h>
55 #include <asm/mpc8xx.h>
59 #if defined(CONFIG_FEC2)
60 #define FEC_MAX_PORTS 2
62 #define FEC_MAX_PORTS 1
66 * Define the fixed address of the FEC hardware.
68 static unsigned int const fec_hw
[] = {
69 #if defined(CONFIG_M5272)
71 #elif defined(CONFIG_M527x)
74 #elif defined(CONFIG_M528x)
77 &(((immap_t
*)IMAP_ADDR
)->im_cpm
.cp_fec
),
81 static unsigned char const fec_mac_default
[] = {
82 0x00, 0xcf, 0x52, 0x00, 0x00, 0x00,
86 * Some hardware gets it MAC address out of local flash memory.
87 * if this is non-zero then assume it is the address to get MAC from.
89 #if defined(CONFIG_NETtel)
90 #define FEC_FLASHMAC 0xf0006006
91 #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
92 #define FEC_FLASHMAC 0xf0006000
93 #elif defined (CONFIG_MTD_KeyTechnology)
94 #define FEC_FLASHMAC 0xffe04000
95 #elif defined(CONFIG_CANCam)
96 #define FEC_FLASHMAC 0xf0020000
97 #elif defined (CONFIG_M5272C3)
98 #define FEC_FLASHMAC (0xffe04000 + 4)
100 #define FEC_FLASHMAC 0
103 /* Forward declarations of some structures to support different PHYs
108 void (*funct
)(uint mii_reg
, struct net_device
*dev
);
115 const phy_cmd_t
*config
;
116 const phy_cmd_t
*startup
;
117 const phy_cmd_t
*ack_int
;
118 const phy_cmd_t
*shutdown
;
121 /* The number of Tx and Rx buffers. These are allocated from the page
122 * pool. The code may assume these are power of two, so it it best
123 * to keep them that size.
124 * We don't need to allocate pages for the transmitter. We just use
125 * the skbuffer directly.
127 #define FEC_ENET_RX_PAGES 8
128 #define FEC_ENET_RX_FRSIZE 2048
129 #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
130 #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
131 #define FEC_ENET_TX_FRSIZE 2048
132 #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
133 #define TX_RING_SIZE 16 /* Must be power of two */
134 #define TX_RING_MOD_MASK 15 /* for this to work */
136 /* Interrupt events/masks.
138 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
139 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
140 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
141 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
142 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
143 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
144 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
145 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
146 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
147 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
149 /* The FEC stores dest/src/type, data, and checksum for receive packets.
151 #define PKT_MAXBUF_SIZE 1518
152 #define PKT_MINBUF_SIZE 64
153 #define PKT_MAXBLR_SIZE 1520
157 * The 5270/5271/5280/5282 RX control register also contains maximum frame
158 * size bits. Other FEC hardware does not, so we need to take that into
159 * account when setting it.
161 #if defined(CONFIG_M527x) || defined(CONFIG_M528x)
162 #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
164 #define OPT_FRAME_SIZE 0
167 /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
168 * tx_bd_base always point to the base of the buffer descriptors. The
169 * cur_rx and cur_tx point to the currently available buffer.
170 * The dirty_tx tracks the current buffer that is being sent by the
171 * controller. The cur_tx and dirty_tx are equal under both completely
172 * empty and completely full conditions. The empty/ready indicator in
173 * the buffer descriptor determines the actual condition.
175 struct fec_enet_private
{
176 /* Hardware registers of the FEC device */
179 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
180 unsigned char *tx_bounce
[TX_RING_SIZE
];
181 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
185 /* CPM dual port RAM relative addresses.
187 cbd_t
*rx_bd_base
; /* Address of Rx and Tx buffers. */
189 cbd_t
*cur_rx
, *cur_tx
; /* The next free ring entry */
190 cbd_t
*dirty_tx
; /* The ring entries to be free()ed. */
191 struct net_device_stats stats
;
199 phy_info_t
const *phy
;
200 struct work_struct phy_task
;
203 uint mii_phy_task_queued
;
212 unsigned char mac_addr
[ETH_ALEN
];
215 static int fec_enet_open(struct net_device
*dev
);
216 static int fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
217 static void fec_enet_mii(struct net_device
*dev
);
218 static irqreturn_t
fec_enet_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
);
219 static void fec_enet_tx(struct net_device
*dev
);
220 static void fec_enet_rx(struct net_device
*dev
);
221 static int fec_enet_close(struct net_device
*dev
);
222 static struct net_device_stats
*fec_enet_get_stats(struct net_device
*dev
);
223 static void set_multicast_list(struct net_device
*dev
);
224 static void fec_restart(struct net_device
*dev
, int duplex
);
225 static void fec_stop(struct net_device
*dev
);
226 static void fec_set_mac_address(struct net_device
*dev
);
229 /* MII processing. We keep this as simple as possible. Requests are
230 * placed on the list (if there is room). When the request is finished
231 * by the MII, an optional function may be called.
233 typedef struct mii_list
{
235 void (*mii_func
)(uint val
, struct net_device
*dev
);
236 struct mii_list
*mii_next
;
240 static mii_list_t mii_cmds
[NMII
];
241 static mii_list_t
*mii_free
;
242 static mii_list_t
*mii_head
;
243 static mii_list_t
*mii_tail
;
245 static int mii_queue(struct net_device
*dev
, int request
,
246 void (*func
)(uint
, struct net_device
*));
248 /* Make MII read/write commands for the FEC.
250 #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
251 #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
255 /* Transmitter timeout.
257 #define TX_TIMEOUT (2*HZ)
259 /* Register definitions for the PHY.
262 #define MII_REG_CR 0 /* Control Register */
263 #define MII_REG_SR 1 /* Status Register */
264 #define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
265 #define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
266 #define MII_REG_ANAR 4 /* A-N Advertisement Register */
267 #define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
268 #define MII_REG_ANER 6 /* A-N Expansion Register */
269 #define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
270 #define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
272 /* values for phy_status */
274 #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
275 #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
276 #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
277 #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
278 #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
279 #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
280 #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
282 #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
283 #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
284 #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
285 #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
286 #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
287 #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
288 #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
289 #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
293 fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
295 struct fec_enet_private
*fep
;
296 volatile fec_t
*fecp
;
299 fep
= netdev_priv(dev
);
300 fecp
= (volatile fec_t
*)dev
->base_addr
;
303 /* Link is down or autonegotiation is in progress. */
307 /* Fill in a Tx ring entry */
310 #ifndef final_version
311 if (bdp
->cbd_sc
& BD_ENET_TX_READY
) {
312 /* Ooops. All transmit buffers are full. Bail out.
313 * This should not happen, since dev->tbusy should be set.
315 printk("%s: tx queue full!.\n", dev
->name
);
320 /* Clear all of the status flags.
322 bdp
->cbd_sc
&= ~BD_ENET_TX_STATS
;
324 /* Set buffer length and buffer pointer.
326 bdp
->cbd_bufaddr
= __pa(skb
->data
);
327 bdp
->cbd_datlen
= skb
->len
;
330 * On some FEC implementations data must be aligned on
331 * 4-byte boundaries. Use bounce buffers to copy data
332 * and get it aligned. Ugh.
334 if (bdp
->cbd_bufaddr
& 0x3) {
336 index
= bdp
- fep
->tx_bd_base
;
337 memcpy(fep
->tx_bounce
[index
], (void *) bdp
->cbd_bufaddr
, bdp
->cbd_datlen
);
338 bdp
->cbd_bufaddr
= __pa(fep
->tx_bounce
[index
]);
343 fep
->tx_skbuff
[fep
->skb_cur
] = skb
;
345 fep
->stats
.tx_bytes
+= skb
->len
;
346 fep
->skb_cur
= (fep
->skb_cur
+1) & TX_RING_MOD_MASK
;
348 /* Push the data cache so the CPM does not get stale memory
351 flush_dcache_range((unsigned long)skb
->data
,
352 (unsigned long)skb
->data
+ skb
->len
);
354 spin_lock_irq(&fep
->lock
);
356 /* Send it on its way. Tell FEC its ready, interrupt when done,
357 * its the last BD of the frame, and to put the CRC on the end.
360 bdp
->cbd_sc
|= (BD_ENET_TX_READY
| BD_ENET_TX_INTR
361 | BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
363 dev
->trans_start
= jiffies
;
365 /* Trigger transmission start */
366 fecp
->fec_x_des_active
= 0x01000000;
368 /* If this was the last BD in the ring, start at the beginning again.
370 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
) {
371 bdp
= fep
->tx_bd_base
;
376 if (bdp
== fep
->dirty_tx
) {
378 netif_stop_queue(dev
);
381 fep
->cur_tx
= (cbd_t
*)bdp
;
383 spin_unlock_irq(&fep
->lock
);
389 fec_timeout(struct net_device
*dev
)
391 struct fec_enet_private
*fep
= netdev_priv(dev
);
393 printk("%s: transmit timed out.\n", dev
->name
);
394 fep
->stats
.tx_errors
++;
395 #ifndef final_version
400 printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
401 (unsigned long)fep
->cur_tx
, fep
->tx_full
? " (full)" : "",
402 (unsigned long)fep
->dirty_tx
,
403 (unsigned long)fep
->cur_rx
);
405 bdp
= fep
->tx_bd_base
;
406 printk(" tx: %u buffers\n", TX_RING_SIZE
);
407 for (i
= 0 ; i
< TX_RING_SIZE
; i
++) {
408 printk(" %08x: %04x %04x %08x\n",
412 (int) bdp
->cbd_bufaddr
);
416 bdp
= fep
->rx_bd_base
;
417 printk(" rx: %lu buffers\n", (unsigned long) RX_RING_SIZE
);
418 for (i
= 0 ; i
< RX_RING_SIZE
; i
++) {
419 printk(" %08x: %04x %04x %08x\n",
423 (int) bdp
->cbd_bufaddr
);
429 netif_wake_queue(dev
);
432 /* The interrupt handler.
433 * This is called from the MPC core interrupt.
436 fec_enet_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
438 struct net_device
*dev
= dev_id
;
439 volatile fec_t
*fecp
;
443 fecp
= (volatile fec_t
*)dev
->base_addr
;
445 /* Get the interrupt events that caused us to be here.
447 while ((int_events
= fecp
->fec_ievent
) != 0) {
448 fecp
->fec_ievent
= int_events
;
450 /* Handle receive event in its own function.
452 if (int_events
& FEC_ENET_RXF
) {
457 /* Transmit OK, or non-fatal error. Update the buffer
458 descriptors. FEC handles all errors, we just discover
459 them as part of the transmit process.
461 if (int_events
& FEC_ENET_TXF
) {
466 if (int_events
& FEC_ENET_MII
) {
472 return IRQ_RETVAL(handled
);
477 fec_enet_tx(struct net_device
*dev
)
479 struct fec_enet_private
*fep
;
483 fep
= netdev_priv(dev
);
484 spin_lock(&fep
->lock
);
487 while ((bdp
->cbd_sc
&BD_ENET_TX_READY
) == 0) {
488 if (bdp
== fep
->cur_tx
&& fep
->tx_full
== 0) break;
490 skb
= fep
->tx_skbuff
[fep
->skb_dirty
];
491 /* Check for errors. */
492 if (bdp
->cbd_sc
& (BD_ENET_TX_HB
| BD_ENET_TX_LC
|
493 BD_ENET_TX_RL
| BD_ENET_TX_UN
|
495 fep
->stats
.tx_errors
++;
496 if (bdp
->cbd_sc
& BD_ENET_TX_HB
) /* No heartbeat */
497 fep
->stats
.tx_heartbeat_errors
++;
498 if (bdp
->cbd_sc
& BD_ENET_TX_LC
) /* Late collision */
499 fep
->stats
.tx_window_errors
++;
500 if (bdp
->cbd_sc
& BD_ENET_TX_RL
) /* Retrans limit */
501 fep
->stats
.tx_aborted_errors
++;
502 if (bdp
->cbd_sc
& BD_ENET_TX_UN
) /* Underrun */
503 fep
->stats
.tx_fifo_errors
++;
504 if (bdp
->cbd_sc
& BD_ENET_TX_CSL
) /* Carrier lost */
505 fep
->stats
.tx_carrier_errors
++;
507 fep
->stats
.tx_packets
++;
510 #ifndef final_version
511 if (bdp
->cbd_sc
& BD_ENET_TX_READY
)
512 printk("HEY! Enet xmit interrupt and TX_READY.\n");
514 /* Deferred means some collisions occurred during transmit,
515 * but we eventually sent the packet OK.
517 if (bdp
->cbd_sc
& BD_ENET_TX_DEF
)
518 fep
->stats
.collisions
++;
520 /* Free the sk buffer associated with this last transmit.
522 dev_kfree_skb_any(skb
);
523 fep
->tx_skbuff
[fep
->skb_dirty
] = NULL
;
524 fep
->skb_dirty
= (fep
->skb_dirty
+ 1) & TX_RING_MOD_MASK
;
526 /* Update pointer to next buffer descriptor to be transmitted.
528 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
)
529 bdp
= fep
->tx_bd_base
;
533 /* Since we have freed up a buffer, the ring is no longer
538 if (netif_queue_stopped(dev
))
539 netif_wake_queue(dev
);
542 fep
->dirty_tx
= (cbd_t
*)bdp
;
543 spin_unlock(&fep
->lock
);
547 /* During a receive, the cur_rx points to the current incoming buffer.
548 * When we update through the ring, if the next incoming buffer has
549 * not been given to the system, we just set the empty indicator,
550 * effectively tossing the packet.
553 fec_enet_rx(struct net_device
*dev
)
555 struct fec_enet_private
*fep
;
556 volatile fec_t
*fecp
;
562 fep
= netdev_priv(dev
);
563 fecp
= (volatile fec_t
*)dev
->base_addr
;
565 /* First, grab all of the stats for the incoming packet.
566 * These get messed up if we get called due to a busy condition.
570 while (!(bdp
->cbd_sc
& BD_ENET_RX_EMPTY
)) {
572 #ifndef final_version
573 /* Since we have allocated space to hold a complete frame,
574 * the last indicator should be set.
576 if ((bdp
->cbd_sc
& BD_ENET_RX_LAST
) == 0)
577 printk("FEC ENET: rcv is not +last\n");
581 goto rx_processing_done
;
583 /* Check for errors. */
584 if (bdp
->cbd_sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
| BD_ENET_RX_NO
|
585 BD_ENET_RX_CR
| BD_ENET_RX_OV
)) {
586 fep
->stats
.rx_errors
++;
587 if (bdp
->cbd_sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
)) {
588 /* Frame too long or too short. */
589 fep
->stats
.rx_length_errors
++;
591 if (bdp
->cbd_sc
& BD_ENET_RX_NO
) /* Frame alignment */
592 fep
->stats
.rx_frame_errors
++;
593 if (bdp
->cbd_sc
& BD_ENET_RX_CR
) /* CRC Error */
594 fep
->stats
.rx_crc_errors
++;
595 if (bdp
->cbd_sc
& BD_ENET_RX_OV
) /* FIFO overrun */
596 fep
->stats
.rx_crc_errors
++;
599 /* Report late collisions as a frame error.
600 * On this error, the BD is closed, but we don't know what we
601 * have in the buffer. So, just drop this frame on the floor.
603 if (bdp
->cbd_sc
& BD_ENET_RX_CL
) {
604 fep
->stats
.rx_errors
++;
605 fep
->stats
.rx_frame_errors
++;
606 goto rx_processing_done
;
609 /* Process the incoming frame.
611 fep
->stats
.rx_packets
++;
612 pkt_len
= bdp
->cbd_datlen
;
613 fep
->stats
.rx_bytes
+= pkt_len
;
614 data
= (__u8
*)__va(bdp
->cbd_bufaddr
);
616 /* This does 16 byte alignment, exactly what we need.
617 * The packet length includes FCS, but we don't want to
618 * include that when passing upstream as it messes up
619 * bridging applications.
621 skb
= dev_alloc_skb(pkt_len
-4);
624 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
625 fep
->stats
.rx_dropped
++;
628 skb_put(skb
,pkt_len
-4); /* Make room */
629 eth_copy_and_sum(skb
,
630 (unsigned char *)__va(bdp
->cbd_bufaddr
),
632 skb
->protocol
=eth_type_trans(skb
,dev
);
637 /* Clear the status flags for this buffer.
639 bdp
->cbd_sc
&= ~BD_ENET_RX_STATS
;
641 /* Mark the buffer empty.
643 bdp
->cbd_sc
|= BD_ENET_RX_EMPTY
;
645 /* Update BD pointer to next entry.
647 if (bdp
->cbd_sc
& BD_ENET_RX_WRAP
)
648 bdp
= fep
->rx_bd_base
;
653 /* Doing this here will keep the FEC running while we process
654 * incoming frames. On a heavily loaded network, we should be
655 * able to keep up at the expense of system resources.
657 fecp
->fec_r_des_active
= 0x01000000;
659 } /* while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) */
660 fep
->cur_rx
= (cbd_t
*)bdp
;
663 /* Doing this here will allow us to process all frames in the
664 * ring before the FEC is allowed to put more there. On a heavily
665 * loaded network, some frames may be lost. Unfortunately, this
666 * increases the interrupt overhead since we can potentially work
667 * our way back to the interrupt return only to come right back
670 fecp
->fec_r_des_active
= 0x01000000;
676 fec_enet_mii(struct net_device
*dev
)
678 struct fec_enet_private
*fep
;
683 fep
= netdev_priv(dev
);
685 mii_reg
= ep
->fec_mii_data
;
687 if ((mip
= mii_head
) == NULL
) {
688 printk("MII and no head!\n");
692 if (mip
->mii_func
!= NULL
)
693 (*(mip
->mii_func
))(mii_reg
, dev
);
695 mii_head
= mip
->mii_next
;
696 mip
->mii_next
= mii_free
;
699 if ((mip
= mii_head
) != NULL
)
700 ep
->fec_mii_data
= mip
->mii_regval
;
704 mii_queue(struct net_device
*dev
, int regval
, void (*func
)(uint
, struct net_device
*))
706 struct fec_enet_private
*fep
;
711 /* Add PHY address to register command.
713 fep
= netdev_priv(dev
);
714 regval
|= fep
->phy_addr
<< 23;
721 if ((mip
= mii_free
) != NULL
) {
722 mii_free
= mip
->mii_next
;
723 mip
->mii_regval
= regval
;
724 mip
->mii_func
= func
;
725 mip
->mii_next
= NULL
;
727 mii_tail
->mii_next
= mip
;
731 mii_head
= mii_tail
= mip
;
732 fep
->hwp
->fec_mii_data
= regval
;
739 restore_flags(flags
);
744 static void mii_do_cmd(struct net_device
*dev
, const phy_cmd_t
*c
)
751 for(k
= 0; (c
+k
)->mii_data
!= mk_mii_end
; k
++) {
752 mii_queue(dev
, (c
+k
)->mii_data
, (c
+k
)->funct
);
756 static void mii_parse_sr(uint mii_reg
, struct net_device
*dev
)
758 struct fec_enet_private
*fep
= netdev_priv(dev
);
759 volatile uint
*s
= &(fep
->phy_status
);
762 status
= *s
& ~(PHY_STAT_LINK
| PHY_STAT_FAULT
| PHY_STAT_ANC
);
764 if (mii_reg
& 0x0004)
765 status
|= PHY_STAT_LINK
;
766 if (mii_reg
& 0x0010)
767 status
|= PHY_STAT_FAULT
;
768 if (mii_reg
& 0x0020)
769 status
|= PHY_STAT_ANC
;
774 static void mii_parse_cr(uint mii_reg
, struct net_device
*dev
)
776 struct fec_enet_private
*fep
= netdev_priv(dev
);
777 volatile uint
*s
= &(fep
->phy_status
);
779 *s
&= ~(PHY_CONF_ANE
| PHY_CONF_LOOP
);
781 if (mii_reg
& 0x1000)
783 if (mii_reg
& 0x4000)
787 static void mii_parse_anar(uint mii_reg
, struct net_device
*dev
)
789 struct fec_enet_private
*fep
= netdev_priv(dev
);
790 volatile uint
*s
= &(fep
->phy_status
);
792 *s
&= ~(PHY_CONF_SPMASK
);
794 if (mii_reg
& 0x0020)
795 *s
|= PHY_CONF_10HDX
;
796 if (mii_reg
& 0x0040)
797 *s
|= PHY_CONF_10FDX
;
798 if (mii_reg
& 0x0080)
799 *s
|= PHY_CONF_100HDX
;
800 if (mii_reg
& 0x00100)
801 *s
|= PHY_CONF_100FDX
;
804 /* ------------------------------------------------------------------------- */
805 /* The Level one LXT970 is used by many boards */
807 #define MII_LXT970_MIRROR 16 /* Mirror register */
808 #define MII_LXT970_IER 17 /* Interrupt Enable Register */
809 #define MII_LXT970_ISR 18 /* Interrupt Status Register */
810 #define MII_LXT970_CONFIG 19 /* Configuration Register */
811 #define MII_LXT970_CSR 20 /* Chip Status Register */
813 static void mii_parse_lxt970_csr(uint mii_reg
, struct net_device
*dev
)
815 struct fec_enet_private
*fep
= netdev_priv(dev
);
816 volatile uint
*s
= &(fep
->phy_status
);
819 status
= *s
& ~(PHY_STAT_SPMASK
);
820 if (mii_reg
& 0x0800) {
821 if (mii_reg
& 0x1000)
822 status
|= PHY_STAT_100FDX
;
824 status
|= PHY_STAT_100HDX
;
826 if (mii_reg
& 0x1000)
827 status
|= PHY_STAT_10FDX
;
829 status
|= PHY_STAT_10HDX
;
834 static phy_cmd_t
const phy_cmd_lxt970_config
[] = {
835 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
836 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
839 static phy_cmd_t
const phy_cmd_lxt970_startup
[] = { /* enable interrupts */
840 { mk_mii_write(MII_LXT970_IER
, 0x0002), NULL
},
841 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
844 static phy_cmd_t
const phy_cmd_lxt970_ack_int
[] = {
845 /* read SR and ISR to acknowledge */
846 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
847 { mk_mii_read(MII_LXT970_ISR
), NULL
},
849 /* find out the current status */
850 { mk_mii_read(MII_LXT970_CSR
), mii_parse_lxt970_csr
},
853 static phy_cmd_t
const phy_cmd_lxt970_shutdown
[] = { /* disable interrupts */
854 { mk_mii_write(MII_LXT970_IER
, 0x0000), NULL
},
857 static phy_info_t
const phy_info_lxt970
= {
860 phy_cmd_lxt970_config
,
861 phy_cmd_lxt970_startup
,
862 phy_cmd_lxt970_ack_int
,
863 phy_cmd_lxt970_shutdown
866 /* ------------------------------------------------------------------------- */
867 /* The Level one LXT971 is used on some of my custom boards */
869 /* register definitions for the 971 */
871 #define MII_LXT971_PCR 16 /* Port Control Register */
872 #define MII_LXT971_SR2 17 /* Status Register 2 */
873 #define MII_LXT971_IER 18 /* Interrupt Enable Register */
874 #define MII_LXT971_ISR 19 /* Interrupt Status Register */
875 #define MII_LXT971_LCR 20 /* LED Control Register */
876 #define MII_LXT971_TCR 30 /* Transmit Control Register */
879 * I had some nice ideas of running the MDIO faster...
880 * The 971 should support 8MHz and I tried it, but things acted really
881 * weird, so 2.5 MHz ought to be enough for anyone...
884 static void mii_parse_lxt971_sr2(uint mii_reg
, struct net_device
*dev
)
886 struct fec_enet_private
*fep
= netdev_priv(dev
);
887 volatile uint
*s
= &(fep
->phy_status
);
890 status
= *s
& ~(PHY_STAT_SPMASK
| PHY_STAT_LINK
| PHY_STAT_ANC
);
892 if (mii_reg
& 0x0400) {
894 status
|= PHY_STAT_LINK
;
898 if (mii_reg
& 0x0080)
899 status
|= PHY_STAT_ANC
;
900 if (mii_reg
& 0x4000) {
901 if (mii_reg
& 0x0200)
902 status
|= PHY_STAT_100FDX
;
904 status
|= PHY_STAT_100HDX
;
906 if (mii_reg
& 0x0200)
907 status
|= PHY_STAT_10FDX
;
909 status
|= PHY_STAT_10HDX
;
911 if (mii_reg
& 0x0008)
912 status
|= PHY_STAT_FAULT
;
917 static phy_cmd_t
const phy_cmd_lxt971_config
[] = {
918 /* limit to 10MBit because my prototype board
919 * doesn't work with 100. */
920 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
921 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
922 { mk_mii_read(MII_LXT971_SR2
), mii_parse_lxt971_sr2
},
925 static phy_cmd_t
const phy_cmd_lxt971_startup
[] = { /* enable interrupts */
926 { mk_mii_write(MII_LXT971_IER
, 0x00f2), NULL
},
927 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
928 { mk_mii_write(MII_LXT971_LCR
, 0xd422), NULL
}, /* LED config */
929 /* Somehow does the 971 tell me that the link is down
930 * the first read after power-up.
931 * read here to get a valid value in ack_int */
932 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
935 static phy_cmd_t
const phy_cmd_lxt971_ack_int
[] = {
936 /* find out the current status */
937 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
938 { mk_mii_read(MII_LXT971_SR2
), mii_parse_lxt971_sr2
},
939 /* we only need to read ISR to acknowledge */
940 { mk_mii_read(MII_LXT971_ISR
), NULL
},
943 static phy_cmd_t
const phy_cmd_lxt971_shutdown
[] = { /* disable interrupts */
944 { mk_mii_write(MII_LXT971_IER
, 0x0000), NULL
},
947 static phy_info_t
const phy_info_lxt971
= {
950 phy_cmd_lxt971_config
,
951 phy_cmd_lxt971_startup
,
952 phy_cmd_lxt971_ack_int
,
953 phy_cmd_lxt971_shutdown
956 /* ------------------------------------------------------------------------- */
957 /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
959 /* register definitions */
961 #define MII_QS6612_MCR 17 /* Mode Control Register */
962 #define MII_QS6612_FTR 27 /* Factory Test Register */
963 #define MII_QS6612_MCO 28 /* Misc. Control Register */
964 #define MII_QS6612_ISR 29 /* Interrupt Source Register */
965 #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
966 #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
968 static void mii_parse_qs6612_pcr(uint mii_reg
, struct net_device
*dev
)
970 struct fec_enet_private
*fep
= netdev_priv(dev
);
971 volatile uint
*s
= &(fep
->phy_status
);
974 status
= *s
& ~(PHY_STAT_SPMASK
);
976 switch((mii_reg
>> 2) & 7) {
977 case 1: status
|= PHY_STAT_10HDX
; break;
978 case 2: status
|= PHY_STAT_100HDX
; break;
979 case 5: status
|= PHY_STAT_10FDX
; break;
980 case 6: status
|= PHY_STAT_100FDX
; break;
986 static phy_cmd_t
const phy_cmd_qs6612_config
[] = {
987 /* The PHY powers up isolated on the RPX,
988 * so send a command to allow operation.
990 { mk_mii_write(MII_QS6612_PCR
, 0x0dc0), NULL
},
992 /* parse cr and anar to get some info */
993 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
994 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
997 static phy_cmd_t
const phy_cmd_qs6612_startup
[] = { /* enable interrupts */
998 { mk_mii_write(MII_QS6612_IMR
, 0x003a), NULL
},
999 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1002 static phy_cmd_t
const phy_cmd_qs6612_ack_int
[] = {
1003 /* we need to read ISR, SR and ANER to acknowledge */
1004 { mk_mii_read(MII_QS6612_ISR
), NULL
},
1005 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1006 { mk_mii_read(MII_REG_ANER
), NULL
},
1008 /* read pcr to get info */
1009 { mk_mii_read(MII_QS6612_PCR
), mii_parse_qs6612_pcr
},
1012 static phy_cmd_t
const phy_cmd_qs6612_shutdown
[] = { /* disable interrupts */
1013 { mk_mii_write(MII_QS6612_IMR
, 0x0000), NULL
},
1016 static phy_info_t
const phy_info_qs6612
= {
1019 phy_cmd_qs6612_config
,
1020 phy_cmd_qs6612_startup
,
1021 phy_cmd_qs6612_ack_int
,
1022 phy_cmd_qs6612_shutdown
1025 /* ------------------------------------------------------------------------- */
1026 /* AMD AM79C874 phy */
1028 /* register definitions for the 874 */
1030 #define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
1031 #define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
1032 #define MII_AM79C874_DR 18 /* Diagnostic Register */
1033 #define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
1034 #define MII_AM79C874_MCR 21 /* ModeControl Register */
1035 #define MII_AM79C874_DC 23 /* Disconnect Counter */
1036 #define MII_AM79C874_REC 24 /* Recieve Error Counter */
1038 static void mii_parse_am79c874_dr(uint mii_reg
, struct net_device
*dev
)
1040 struct fec_enet_private
*fep
= netdev_priv(dev
);
1041 volatile uint
*s
= &(fep
->phy_status
);
1044 status
= *s
& ~(PHY_STAT_SPMASK
| PHY_STAT_ANC
);
1046 if (mii_reg
& 0x0080)
1047 status
|= PHY_STAT_ANC
;
1048 if (mii_reg
& 0x0400)
1049 status
|= ((mii_reg
& 0x0800) ? PHY_STAT_100FDX
: PHY_STAT_100HDX
);
1051 status
|= ((mii_reg
& 0x0800) ? PHY_STAT_10FDX
: PHY_STAT_10HDX
);
1056 static phy_cmd_t
const phy_cmd_am79c874_config
[] = {
1057 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1058 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1059 { mk_mii_read(MII_AM79C874_DR
), mii_parse_am79c874_dr
},
1062 static phy_cmd_t
const phy_cmd_am79c874_startup
[] = { /* enable interrupts */
1063 { mk_mii_write(MII_AM79C874_ICSR
, 0xff00), NULL
},
1064 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1065 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1068 static phy_cmd_t
const phy_cmd_am79c874_ack_int
[] = {
1069 /* find out the current status */
1070 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1071 { mk_mii_read(MII_AM79C874_DR
), mii_parse_am79c874_dr
},
1072 /* we only need to read ISR to acknowledge */
1073 { mk_mii_read(MII_AM79C874_ICSR
), NULL
},
1076 static phy_cmd_t
const phy_cmd_am79c874_shutdown
[] = { /* disable interrupts */
1077 { mk_mii_write(MII_AM79C874_ICSR
, 0x0000), NULL
},
1080 static phy_info_t
const phy_info_am79c874
= {
1083 phy_cmd_am79c874_config
,
1084 phy_cmd_am79c874_startup
,
1085 phy_cmd_am79c874_ack_int
,
1086 phy_cmd_am79c874_shutdown
1090 /* ------------------------------------------------------------------------- */
1091 /* Kendin KS8721BL phy */
1093 /* register definitions for the 8721 */
1095 #define MII_KS8721BL_RXERCR 21
1096 #define MII_KS8721BL_ICSR 22
1097 #define MII_KS8721BL_PHYCR 31
1099 static phy_cmd_t
const phy_cmd_ks8721bl_config
[] = {
1100 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1101 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1104 static phy_cmd_t
const phy_cmd_ks8721bl_startup
[] = { /* enable interrupts */
1105 { mk_mii_write(MII_KS8721BL_ICSR
, 0xff00), NULL
},
1106 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1107 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1110 static phy_cmd_t
const phy_cmd_ks8721bl_ack_int
[] = {
1111 /* find out the current status */
1112 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1113 /* we only need to read ISR to acknowledge */
1114 { mk_mii_read(MII_KS8721BL_ICSR
), NULL
},
1117 static phy_cmd_t
const phy_cmd_ks8721bl_shutdown
[] = { /* disable interrupts */
1118 { mk_mii_write(MII_KS8721BL_ICSR
, 0x0000), NULL
},
1121 static phy_info_t
const phy_info_ks8721bl
= {
1124 phy_cmd_ks8721bl_config
,
1125 phy_cmd_ks8721bl_startup
,
1126 phy_cmd_ks8721bl_ack_int
,
1127 phy_cmd_ks8721bl_shutdown
1130 /* ------------------------------------------------------------------------- */
1132 static phy_info_t
const * const phy_info
[] = {
1141 /* ------------------------------------------------------------------------- */
1143 #ifdef CONFIG_RPXCLASSIC
1145 mii_link_interrupt(void *dev_id
);
1148 mii_link_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
);
1151 #if defined(CONFIG_M5272)
1154 * Code specific to Coldfire 5272 setup.
1156 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1158 volatile unsigned long *icrp
;
1159 static const struct idesc
{
1162 irqreturn_t (*handler
)(int, void *, struct pt_regs
*);
1164 { "fec(RX)", 86, fec_enet_interrupt
},
1165 { "fec(TX)", 87, fec_enet_interrupt
},
1166 { "fec(OTHER)", 88, fec_enet_interrupt
},
1167 { "fec(MII)", 66, mii_link_interrupt
},
1171 /* Setup interrupt handlers. */
1172 for (idp
= id
; idp
->name
; idp
++) {
1173 if (request_irq(idp
->irq
, idp
->handler
, 0, idp
->name
, dev
) != 0)
1174 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp
->name
, idp
->irq
);
1177 /* Unmask interrupt at ColdFire 5272 SIM */
1178 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR3
);
1180 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1181 *icrp
= (*icrp
& 0x70777777) | 0x0d000000;
1184 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1186 volatile fec_t
*fecp
;
1189 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1190 fecp
->fec_x_cntrl
= 0x00;
1193 * Set MII speed to 2.5 MHz
1194 * See 5272 manual section 11.5.8: MSCR
1196 fep
->phy_speed
= ((((MCF_CLK
/ 4) / (2500000 / 10)) + 5) / 10) * 2;
1197 fecp
->fec_mii_speed
= fep
->phy_speed
;
1199 fec_restart(dev
, 0);
1202 static void __inline__
fec_get_mac(struct net_device
*dev
)
1204 struct fec_enet_private
*fep
= netdev_priv(dev
);
1205 volatile fec_t
*fecp
;
1206 unsigned char *iap
, tmpaddr
[6];
1213 * Get MAC address from FLASH.
1214 * If it is all 1's or 0's, use the default.
1217 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1218 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1219 iap
= fec_mac_default
;
1220 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1221 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1222 iap
= fec_mac_default
;
1224 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1225 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1229 for (i
=0; i
<ETH_ALEN
; i
++)
1230 dev
->dev_addr
[i
] = fep
->mac_addr
[i
] = *iap
++;
1232 /* Adjust MAC if using default MAC address */
1233 if (iap
== fec_mac_default
) {
1234 dev
->dev_addr
[ETH_ALEN
-1] = fep
->mac_addr
[ETH_ALEN
-1] =
1235 iap
[ETH_ALEN
-1] + fep
->index
;
1239 static void __inline__
fec_enable_phy_intr(void)
1243 static void __inline__
fec_disable_phy_intr(void)
1245 volatile unsigned long *icrp
;
1246 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1247 *icrp
= (*icrp
& 0x70777777) | 0x08000000;
1250 static void __inline__
fec_phy_ack_intr(void)
1252 volatile unsigned long *icrp
;
1253 /* Acknowledge the interrupt */
1254 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1255 *icrp
= (*icrp
& 0x77777777) | 0x08000000;
1258 static void __inline__
fec_localhw_setup(void)
1263 * Do not need to make region uncached on 5272.
1265 static void __inline__
fec_uncache(unsigned long addr
)
1269 /* ------------------------------------------------------------------------- */
1271 #elif defined(CONFIG_M527x) || defined(CONFIG_M528x)
1274 * Code specific to Coldfire 5270/5271/5274/5275 and 5280/5282 setups.
1276 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1278 struct fec_enet_private
*fep
;
1280 static const struct idesc
{
1286 { "fec(TXFIFO)", 25 },
1287 { "fec(TXCR)", 26 },
1292 { "fec(HBERR)", 31 },
1294 { "fec(EBERR)", 33 },
1295 { "fec(BABT)", 34 },
1296 { "fec(BABR)", 35 },
1300 fep
= netdev_priv(dev
);
1301 b
= (fep
->index
) ? 128 : 64;
1303 /* Setup interrupt handlers. */
1304 for (idp
= id
; idp
->name
; idp
++) {
1305 if (request_irq(b
+idp
->irq
, fec_enet_interrupt
, 0, idp
->name
, dev
) != 0)
1306 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp
->name
, b
+idp
->irq
);
1309 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
1311 volatile unsigned char *icrp
;
1312 volatile unsigned long *imrp
;
1315 b
= (fep
->index
) ? MCFICM_INTC1
: MCFICM_INTC0
;
1316 icrp
= (volatile unsigned char *) (MCF_IPSBAR
+ b
+
1318 for (i
= 23; (i
< 36); i
++)
1321 imrp
= (volatile unsigned long *) (MCF_IPSBAR
+ b
+
1323 *imrp
&= ~0x0000000f;
1324 imrp
= (volatile unsigned long *) (MCF_IPSBAR
+ b
+
1326 *imrp
&= ~0xff800001;
1329 #if defined(CONFIG_M528x)
1330 /* Set up gpio outputs for MII lines */
1332 volatile unsigned short *gpio_paspar
;
1334 gpio_paspar
= (volatile unsigned short *) (MCF_IPSBAR
+
1336 *gpio_paspar
= 0x0f00;
1341 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1343 volatile fec_t
*fecp
;
1346 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1347 fecp
->fec_x_cntrl
= 0x00;
1350 * Set MII speed to 2.5 MHz
1351 * See 5282 manual section 17.5.4.7: MSCR
1353 fep
->phy_speed
= ((((MCF_CLK
/ 2) / (2500000 / 10)) + 5) / 10) * 2;
1354 fecp
->fec_mii_speed
= fep
->phy_speed
;
1356 fec_restart(dev
, 0);
1359 static void __inline__
fec_get_mac(struct net_device
*dev
)
1361 struct fec_enet_private
*fep
= netdev_priv(dev
);
1362 volatile fec_t
*fecp
;
1363 unsigned char *iap
, tmpaddr
[6];
1370 * Get MAC address from FLASH.
1371 * If it is all 1's or 0's, use the default.
1374 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1375 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1376 iap
= fec_mac_default
;
1377 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1378 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1379 iap
= fec_mac_default
;
1381 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1382 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1386 for (i
=0; i
<ETH_ALEN
; i
++)
1387 dev
->dev_addr
[i
] = fep
->mac_addr
[i
] = *iap
++;
1389 /* Adjust MAC if using default MAC address */
1390 if (iap
== fec_mac_default
) {
1391 dev
->dev_addr
[ETH_ALEN
-1] = fep
->mac_addr
[ETH_ALEN
-1] =
1392 iap
[ETH_ALEN
-1] + fep
->index
;
1396 static void __inline__
fec_enable_phy_intr(void)
1400 static void __inline__
fec_disable_phy_intr(void)
1404 static void __inline__
fec_phy_ack_intr(void)
1408 static void __inline__
fec_localhw_setup(void)
1413 * Do not need to make region uncached on 5272.
1415 static void __inline__
fec_uncache(unsigned long addr
)
1419 /* ------------------------------------------------------------------------- */
1424 * Code sepcific to the MPC860T setup.
1426 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1428 volatile immap_t
*immap
;
1430 immap
= (immap_t
*)IMAP_ADDR
; /* pointer to internal registers */
1432 if (request_8xxirq(FEC_INTERRUPT
, fec_enet_interrupt
, 0, "fec", dev
) != 0)
1433 panic("Could not allocate FEC IRQ!");
1435 #ifdef CONFIG_RPXCLASSIC
1436 /* Make Port C, bit 15 an input that causes interrupts.
1438 immap
->im_ioport
.iop_pcpar
&= ~0x0001;
1439 immap
->im_ioport
.iop_pcdir
&= ~0x0001;
1440 immap
->im_ioport
.iop_pcso
&= ~0x0001;
1441 immap
->im_ioport
.iop_pcint
|= 0x0001;
1442 cpm_install_handler(CPMVEC_PIO_PC15
, mii_link_interrupt
, dev
);
1444 /* Make LEDS reflect Link status.
1446 *((uint
*) RPX_CSR_ADDR
) &= ~BCSR2_FETHLEDMODE
;
1449 if (request_8xxirq(SIU_IRQ2
, mii_link_interrupt
, 0, "mii", dev
) != 0)
1450 panic("Could not allocate MII IRQ!");
1454 static void __inline__
fec_get_mac(struct net_device
*dev
)
1456 struct fec_enet_private
*fep
= netdev_priv(dev
);
1457 unsigned char *iap
, tmpaddr
[6];
1461 iap
= bd
->bi_enetaddr
;
1464 #ifdef CONFIG_RPXCLASSIC
1465 /* The Embedded Planet boards have only one MAC address in
1466 * the EEPROM, but can have two Ethernet ports. For the
1467 * FEC port, we create another address by setting one of
1468 * the address bits above something that would have (up to
1469 * now) been allocated.
1472 tmpaddr
[i
] = *iap
++;
1478 dev
->dev_addr
[i
] = fep
->mac_addr
[i
] = *iap
++;
1481 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1483 extern uint
_get_IMMR(void);
1484 volatile immap_t
*immap
;
1485 volatile fec_t
*fecp
;
1488 immap
= (immap_t
*)IMAP_ADDR
; /* pointer to internal registers */
1490 /* Configure all of port D for MII.
1492 immap
->im_ioport
.iop_pdpar
= 0x1fff;
1494 /* Bits moved from Rev. D onward.
1496 if ((_get_IMMR() & 0xffff) < 0x0501)
1497 immap
->im_ioport
.iop_pddir
= 0x1c58; /* Pre rev. D */
1499 immap
->im_ioport
.iop_pddir
= 0x1fff; /* Rev. D and later */
1501 /* Set MII speed to 2.5 MHz
1503 fecp
->fec_mii_speed
= fep
->phy_speed
=
1504 ((bd
->bi_busfreq
* 1000000) / 2500000) & 0x7e;
1507 static void __inline__
fec_enable_phy_intr(void)
1509 volatile fec_t
*fecp
;
1513 /* Enable MII command finished interrupt
1515 fecp
->fec_ivec
= (FEC_INTERRUPT
/2) << 29;
1518 static void __inline__
fec_disable_phy_intr(void)
1522 static void __inline__
fec_phy_ack_intr(void)
1526 static void __inline__
fec_localhw_setup(void)
1528 volatile fec_t
*fecp
;
1531 fecp
->fec_r_hash
= PKT_MAXBUF_SIZE
;
1532 /* Enable big endian and don't care about SDMA FC.
1534 fecp
->fec_fun_code
= 0x78000000;
1537 static void __inline__
fec_uncache(unsigned long addr
)
1540 pte
= va_to_pte(mem_addr
);
1541 pte_val(*pte
) |= _PAGE_NO_CACHE
;
1542 flush_tlb_page(init_mm
.mmap
, mem_addr
);
1547 /* ------------------------------------------------------------------------- */
1549 static void mii_display_status(struct net_device
*dev
)
1551 struct fec_enet_private
*fep
= netdev_priv(dev
);
1552 volatile uint
*s
= &(fep
->phy_status
);
1554 if (!fep
->link
&& !fep
->old_link
) {
1555 /* Link is still down - don't print anything */
1559 printk("%s: status: ", dev
->name
);
1562 printk("link down");
1566 switch(*s
& PHY_STAT_SPMASK
) {
1567 case PHY_STAT_100FDX
: printk(", 100MBit Full Duplex"); break;
1568 case PHY_STAT_100HDX
: printk(", 100MBit Half Duplex"); break;
1569 case PHY_STAT_10FDX
: printk(", 10MBit Full Duplex"); break;
1570 case PHY_STAT_10HDX
: printk(", 10MBit Half Duplex"); break;
1572 printk(", Unknown speed/duplex");
1575 if (*s
& PHY_STAT_ANC
)
1576 printk(", auto-negotiation complete");
1579 if (*s
& PHY_STAT_FAULT
)
1580 printk(", remote fault");
1585 static void mii_display_config(struct net_device
*dev
)
1587 struct fec_enet_private
*fep
= netdev_priv(dev
);
1588 volatile uint
*s
= &(fep
->phy_status
);
1591 ** When we get here, phy_task is already removed from
1592 ** the workqueue. It is thus safe to allow to reuse it.
1594 fep
->mii_phy_task_queued
= 0;
1595 printk("%s: config: auto-negotiation ", dev
->name
);
1597 if (*s
& PHY_CONF_ANE
)
1602 if (*s
& PHY_CONF_100FDX
)
1604 if (*s
& PHY_CONF_100HDX
)
1606 if (*s
& PHY_CONF_10FDX
)
1608 if (*s
& PHY_CONF_10HDX
)
1610 if (!(*s
& PHY_CONF_SPMASK
))
1611 printk(", No speed/duplex selected?");
1613 if (*s
& PHY_CONF_LOOP
)
1614 printk(", loopback enabled");
1618 fep
->sequence_done
= 1;
1621 static void mii_relink(struct net_device
*dev
)
1623 struct fec_enet_private
*fep
= netdev_priv(dev
);
1627 ** When we get here, phy_task is already removed from
1628 ** the workqueue. It is thus safe to allow to reuse it.
1630 fep
->mii_phy_task_queued
= 0;
1631 fep
->link
= (fep
->phy_status
& PHY_STAT_LINK
) ? 1 : 0;
1632 mii_display_status(dev
);
1633 fep
->old_link
= fep
->link
;
1638 & (PHY_STAT_100FDX
| PHY_STAT_10FDX
))
1640 fec_restart(dev
, duplex
);
1646 enable_irq(fep
->mii_irq
);
1651 /* mii_queue_relink is called in interrupt context from mii_link_interrupt */
1652 static void mii_queue_relink(uint mii_reg
, struct net_device
*dev
)
1654 struct fec_enet_private
*fep
= netdev_priv(dev
);
1657 ** We cannot queue phy_task twice in the workqueue. It
1658 ** would cause an endless loop in the workqueue.
1659 ** Fortunately, if the last mii_relink entry has not yet been
1660 ** executed now, it will do the job for the current interrupt,
1661 ** which is just what we want.
1663 if (fep
->mii_phy_task_queued
)
1666 fep
->mii_phy_task_queued
= 1;
1667 INIT_WORK(&fep
->phy_task
, (void*)mii_relink
, dev
);
1668 schedule_work(&fep
->phy_task
);
1671 /* mii_queue_config is called in user context from fec_enet_open */
1672 static void mii_queue_config(uint mii_reg
, struct net_device
*dev
)
1674 struct fec_enet_private
*fep
= netdev_priv(dev
);
1676 if (fep
->mii_phy_task_queued
)
1679 fep
->mii_phy_task_queued
= 1;
1680 INIT_WORK(&fep
->phy_task
, (void*)mii_display_config
, dev
);
1681 schedule_work(&fep
->phy_task
);
1684 phy_cmd_t
const phy_cmd_relink
[] = {
1685 { mk_mii_read(MII_REG_CR
), mii_queue_relink
},
1688 phy_cmd_t
const phy_cmd_config
[] = {
1689 { mk_mii_read(MII_REG_CR
), mii_queue_config
},
1693 /* Read remainder of PHY ID.
1696 mii_discover_phy3(uint mii_reg
, struct net_device
*dev
)
1698 struct fec_enet_private
*fep
;
1701 fep
= netdev_priv(dev
);
1702 fep
->phy_id
|= (mii_reg
& 0xffff);
1703 printk("fec: PHY @ 0x%x, ID 0x%08x", fep
->phy_addr
, fep
->phy_id
);
1705 for(i
= 0; phy_info
[i
]; i
++) {
1706 if(phy_info
[i
]->id
== (fep
->phy_id
>> 4))
1711 printk(" -- %s\n", phy_info
[i
]->name
);
1713 printk(" -- unknown PHY!\n");
1715 fep
->phy
= phy_info
[i
];
1716 fep
->phy_id_done
= 1;
1719 /* Scan all of the MII PHY addresses looking for someone to respond
1720 * with a valid ID. This usually happens quickly.
1723 mii_discover_phy(uint mii_reg
, struct net_device
*dev
)
1725 struct fec_enet_private
*fep
;
1726 volatile fec_t
*fecp
;
1729 fep
= netdev_priv(dev
);
1732 if (fep
->phy_addr
< 32) {
1733 if ((phytype
= (mii_reg
& 0xffff)) != 0xffff && phytype
!= 0) {
1735 /* Got first part of ID, now get remainder.
1737 fep
->phy_id
= phytype
<< 16;
1738 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR2
),
1743 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
),
1747 printk("FEC: No PHY device found.\n");
1748 /* Disable external MII interface */
1749 fecp
->fec_mii_speed
= fep
->phy_speed
= 0;
1750 fec_disable_phy_intr();
1754 /* This interrupt occurs when the PHY detects a link change.
1756 #ifdef CONFIG_RPXCLASSIC
1758 mii_link_interrupt(void *dev_id
)
1761 mii_link_interrupt(int irq
, void * dev_id
, struct pt_regs
* regs
)
1764 struct net_device
*dev
= dev_id
;
1765 struct fec_enet_private
*fep
= netdev_priv(dev
);
1770 disable_irq(fep
->mii_irq
); /* disable now, enable later */
1773 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1774 mii_do_cmd(dev
, phy_cmd_relink
); /* restart and display status */
1780 fec_enet_open(struct net_device
*dev
)
1782 struct fec_enet_private
*fep
= netdev_priv(dev
);
1784 /* I should reset the ring buffers here, but I don't yet know
1785 * a simple way to do that.
1787 fec_set_mac_address(dev
);
1789 fep
->sequence_done
= 0;
1793 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1794 mii_do_cmd(dev
, fep
->phy
->config
);
1795 mii_do_cmd(dev
, phy_cmd_config
); /* display configuration */
1797 /* FIXME: use netif_carrier_{on,off} ; this polls
1798 * until link is up which is wrong... could be
1799 * 30 seconds or more we are trapped in here. -jgarzik
1801 while(!fep
->sequence_done
)
1804 mii_do_cmd(dev
, fep
->phy
->startup
);
1806 /* Set the initial link state to true. A lot of hardware
1807 * based on this device does not implement a PHY interrupt,
1808 * so we are never notified of link change.
1812 fep
->link
= 1; /* lets just try it and see */
1813 /* no phy, go full duplex, it's most likely a hub chip */
1814 fec_restart(dev
, 1);
1817 netif_start_queue(dev
);
1819 return 0; /* Success */
1823 fec_enet_close(struct net_device
*dev
)
1825 struct fec_enet_private
*fep
= netdev_priv(dev
);
1827 /* Don't know what to do yet.
1830 netif_stop_queue(dev
);
1836 static struct net_device_stats
*fec_enet_get_stats(struct net_device
*dev
)
1838 struct fec_enet_private
*fep
= netdev_priv(dev
);
1843 /* Set or clear the multicast filter for this adaptor.
1844 * Skeleton taken from sunlance driver.
1845 * The CPM Ethernet implementation allows Multicast as well as individual
1846 * MAC address filtering. Some of the drivers check to make sure it is
1847 * a group multicast address, and discard those that are not. I guess I
1848 * will do the same for now, but just remove the test if you want
1849 * individual filtering as well (do the upper net layers want or support
1850 * this kind of feature?).
1853 #define HASH_BITS 6 /* #bits in hash */
1854 #define CRC32_POLY 0xEDB88320
1856 static void set_multicast_list(struct net_device
*dev
)
1858 struct fec_enet_private
*fep
;
1860 struct dev_mc_list
*dmi
;
1861 unsigned int i
, j
, bit
, data
, crc
;
1864 fep
= netdev_priv(dev
);
1867 if (dev
->flags
&IFF_PROMISC
) {
1868 /* Log any net taps. */
1869 printk("%s: Promiscuous mode enabled.\n", dev
->name
);
1870 ep
->fec_r_cntrl
|= 0x0008;
1873 ep
->fec_r_cntrl
&= ~0x0008;
1875 if (dev
->flags
& IFF_ALLMULTI
) {
1876 /* Catch all multicast addresses, so set the
1877 * filter to all 1's.
1879 ep
->fec_hash_table_high
= 0xffffffff;
1880 ep
->fec_hash_table_low
= 0xffffffff;
1882 /* Clear filter and add the addresses in hash register.
1884 ep
->fec_hash_table_high
= 0;
1885 ep
->fec_hash_table_low
= 0;
1889 for (j
= 0; j
< dev
->mc_count
; j
++, dmi
= dmi
->next
)
1891 /* Only support group multicast for now.
1893 if (!(dmi
->dmi_addr
[0] & 1))
1896 /* calculate crc32 value of mac address
1900 for (i
= 0; i
< dmi
->dmi_addrlen
; i
++)
1902 data
= dmi
->dmi_addr
[i
];
1903 for (bit
= 0; bit
< 8; bit
++, data
>>= 1)
1906 (((crc
^ data
) & 1) ? CRC32_POLY
: 0);
1910 /* only upper 6 bits (HASH_BITS) are used
1911 which point to specific bit in he hash registers
1913 hash
= (crc
>> (32 - HASH_BITS
)) & 0x3f;
1916 ep
->fec_hash_table_high
|= 1 << (hash
- 32);
1918 ep
->fec_hash_table_low
|= 1 << hash
;
1924 /* Set a MAC change in hardware.
1927 fec_set_mac_address(struct net_device
*dev
)
1929 struct fec_enet_private
*fep
;
1930 volatile fec_t
*fecp
;
1932 fep
= netdev_priv(dev
);
1935 /* Set station address. */
1936 fecp
->fec_addr_low
= fep
->mac_addr
[3] | (fep
->mac_addr
[2] << 8) |
1937 (fep
->mac_addr
[1] << 16) | (fep
->mac_addr
[0] << 24);
1938 fecp
->fec_addr_high
= (fep
->mac_addr
[5] << 16) |
1939 (fep
->mac_addr
[4] << 24);
1943 /* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
1946 * XXX: We need to clean up on failure exits here.
1948 int __init
fec_enet_init(struct net_device
*dev
)
1950 struct fec_enet_private
*fep
= netdev_priv(dev
);
1951 unsigned long mem_addr
;
1952 volatile cbd_t
*bdp
;
1954 volatile fec_t
*fecp
;
1956 static int index
= 0;
1958 /* Only allow us to be probed once. */
1959 if (index
>= FEC_MAX_PORTS
)
1962 /* Create an Ethernet device instance.
1964 fecp
= (volatile fec_t
*) fec_hw
[index
];
1969 /* Whack a reset. We should wait for this.
1971 fecp
->fec_ecntrl
= 1;
1974 /* Clear and enable interrupts */
1975 fecp
->fec_ievent
= 0xffc0;
1976 fecp
->fec_imask
= (FEC_ENET_TXF
| FEC_ENET_TXB
|
1977 FEC_ENET_RXF
| FEC_ENET_RXB
| FEC_ENET_MII
);
1978 fecp
->fec_hash_table_high
= 0;
1979 fecp
->fec_hash_table_low
= 0;
1980 fecp
->fec_r_buff_size
= PKT_MAXBLR_SIZE
;
1981 fecp
->fec_ecntrl
= 2;
1982 fecp
->fec_r_des_active
= 0x01000000;
1984 /* Set the Ethernet address. If using multiple Enets on the 8xx,
1985 * this needs some work to get unique addresses.
1987 * This is our default MAC address unless the user changes
1988 * it via eth_mac_addr (our dev->set_mac_addr handler).
1992 /* Allocate memory for buffer descriptors.
1994 if (((RX_RING_SIZE
+ TX_RING_SIZE
) * sizeof(cbd_t
)) > PAGE_SIZE
) {
1995 printk("FEC init error. Need more space.\n");
1996 printk("FEC initialization failed.\n");
1999 mem_addr
= __get_free_page(GFP_KERNEL
);
2000 cbd_base
= (cbd_t
*)mem_addr
;
2001 /* XXX: missing check for allocation failure */
2003 fec_uncache(mem_addr
);
2005 /* Set receive and transmit descriptor base.
2007 fep
->rx_bd_base
= cbd_base
;
2008 fep
->tx_bd_base
= cbd_base
+ RX_RING_SIZE
;
2010 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
2011 fep
->cur_rx
= fep
->rx_bd_base
;
2013 fep
->skb_cur
= fep
->skb_dirty
= 0;
2015 /* Initialize the receive buffer descriptors.
2017 bdp
= fep
->rx_bd_base
;
2018 for (i
=0; i
<FEC_ENET_RX_PAGES
; i
++) {
2022 mem_addr
= __get_free_page(GFP_KERNEL
);
2023 /* XXX: missing check for allocation failure */
2025 fec_uncache(mem_addr
);
2027 /* Initialize the BD for every fragment in the page.
2029 for (j
=0; j
<FEC_ENET_RX_FRPPG
; j
++) {
2030 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
2031 bdp
->cbd_bufaddr
= __pa(mem_addr
);
2032 mem_addr
+= FEC_ENET_RX_FRSIZE
;
2037 /* Set the last buffer to wrap.
2040 bdp
->cbd_sc
|= BD_SC_WRAP
;
2042 /* ...and the same for transmmit.
2044 bdp
= fep
->tx_bd_base
;
2045 for (i
=0, j
=FEC_ENET_TX_FRPPG
; i
<TX_RING_SIZE
; i
++) {
2046 if (j
>= FEC_ENET_TX_FRPPG
) {
2047 mem_addr
= __get_free_page(GFP_KERNEL
);
2050 mem_addr
+= FEC_ENET_TX_FRSIZE
;
2053 fep
->tx_bounce
[i
] = (unsigned char *) mem_addr
;
2055 /* Initialize the BD for every fragment in the page.
2058 bdp
->cbd_bufaddr
= 0;
2062 /* Set the last buffer to wrap.
2065 bdp
->cbd_sc
|= BD_SC_WRAP
;
2067 /* Set receive and transmit descriptor base.
2069 fecp
->fec_r_des_start
= __pa((uint
)(fep
->rx_bd_base
));
2070 fecp
->fec_x_des_start
= __pa((uint
)(fep
->tx_bd_base
));
2072 /* Install our interrupt handlers. This varies depending on
2075 fec_request_intrs(dev
);
2077 dev
->base_addr
= (unsigned long)fecp
;
2079 /* The FEC Ethernet specific entries in the device structure. */
2080 dev
->open
= fec_enet_open
;
2081 dev
->hard_start_xmit
= fec_enet_start_xmit
;
2082 dev
->tx_timeout
= fec_timeout
;
2083 dev
->watchdog_timeo
= TX_TIMEOUT
;
2084 dev
->stop
= fec_enet_close
;
2085 dev
->get_stats
= fec_enet_get_stats
;
2086 dev
->set_multicast_list
= set_multicast_list
;
2088 for (i
=0; i
<NMII
-1; i
++)
2089 mii_cmds
[i
].mii_next
= &mii_cmds
[i
+1];
2090 mii_free
= mii_cmds
;
2092 /* setup MII interface */
2093 fec_set_mii(dev
, fep
);
2095 printk("%s: FEC ENET Version 0.2, ", dev
->name
);
2097 printk("%02x:", dev
->dev_addr
[i
]);
2098 printk("%02x\n", dev
->dev_addr
[5]);
2100 /* Queue up command to detect the PHY and initialize the
2101 * remainder of the interface.
2103 fep
->phy_id_done
= 0;
2105 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
), mii_discover_phy
);
2111 /* This function is called to start or restart the FEC during a link
2112 * change. This only happens when switching between half and full
2116 fec_restart(struct net_device
*dev
, int duplex
)
2118 struct fec_enet_private
*fep
;
2119 volatile cbd_t
*bdp
;
2120 volatile fec_t
*fecp
;
2123 fep
= netdev_priv(dev
);
2126 /* Whack a reset. We should wait for this.
2128 fecp
->fec_ecntrl
= 1;
2131 /* Enable interrupts we wish to service.
2133 fecp
->fec_imask
= (FEC_ENET_TXF
| FEC_ENET_TXB
|
2134 FEC_ENET_RXF
| FEC_ENET_RXB
| FEC_ENET_MII
);
2136 /* Clear any outstanding interrupt.
2138 fecp
->fec_ievent
= 0xffc0;
2139 fec_enable_phy_intr();
2141 /* Set station address.
2143 fecp
->fec_addr_low
= fep
->mac_addr
[3] | (fep
->mac_addr
[2] << 8) |
2144 (fep
->mac_addr
[1] << 16) | (fep
->mac_addr
[0] << 24);
2145 fecp
->fec_addr_high
= (fep
->mac_addr
[5] << 16) |
2146 (fep
->mac_addr
[4] << 24);
2148 for (i
=0; i
<ETH_ALEN
; i
++)
2149 dev
->dev_addr
[i
] = fep
->mac_addr
[i
];
2151 /* Reset all multicast.
2153 fecp
->fec_hash_table_high
= 0;
2154 fecp
->fec_hash_table_low
= 0;
2156 /* Set maximum receive buffer size.
2158 fecp
->fec_r_buff_size
= PKT_MAXBLR_SIZE
;
2160 fec_localhw_setup();
2162 /* Set receive and transmit descriptor base.
2164 fecp
->fec_r_des_start
= __pa((uint
)(fep
->rx_bd_base
));
2165 fecp
->fec_x_des_start
= __pa((uint
)(fep
->tx_bd_base
));
2167 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
2168 fep
->cur_rx
= fep
->rx_bd_base
;
2170 /* Reset SKB transmit buffers.
2172 fep
->skb_cur
= fep
->skb_dirty
= 0;
2173 for (i
=0; i
<=TX_RING_MOD_MASK
; i
++) {
2174 if (fep
->tx_skbuff
[i
] != NULL
) {
2175 dev_kfree_skb_any(fep
->tx_skbuff
[i
]);
2176 fep
->tx_skbuff
[i
] = NULL
;
2180 /* Initialize the receive buffer descriptors.
2182 bdp
= fep
->rx_bd_base
;
2183 for (i
=0; i
<RX_RING_SIZE
; i
++) {
2185 /* Initialize the BD for every fragment in the page.
2187 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
2191 /* Set the last buffer to wrap.
2194 bdp
->cbd_sc
|= BD_SC_WRAP
;
2196 /* ...and the same for transmmit.
2198 bdp
= fep
->tx_bd_base
;
2199 for (i
=0; i
<TX_RING_SIZE
; i
++) {
2201 /* Initialize the BD for every fragment in the page.
2204 bdp
->cbd_bufaddr
= 0;
2208 /* Set the last buffer to wrap.
2211 bdp
->cbd_sc
|= BD_SC_WRAP
;
2216 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;/* MII enable */
2217 fecp
->fec_x_cntrl
= 0x04; /* FD enable */
2220 /* MII enable|No Rcv on Xmit */
2221 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x06;
2222 fecp
->fec_x_cntrl
= 0x00;
2224 fep
->full_duplex
= duplex
;
2228 fecp
->fec_mii_speed
= fep
->phy_speed
;
2230 /* And last, enable the transmit and receive processing.
2232 fecp
->fec_ecntrl
= 2;
2233 fecp
->fec_r_des_active
= 0x01000000;
2237 fec_stop(struct net_device
*dev
)
2239 volatile fec_t
*fecp
;
2240 struct fec_enet_private
*fep
;
2242 fep
= netdev_priv(dev
);
2245 fecp
->fec_x_cntrl
= 0x01; /* Graceful transmit stop */
2247 while(!(fecp
->fec_ievent
& 0x10000000));
2249 /* Whack a reset. We should wait for this.
2251 fecp
->fec_ecntrl
= 1;
2254 /* Clear outstanding MII command interrupts.
2256 fecp
->fec_ievent
= FEC_ENET_MII
;
2257 fec_enable_phy_intr();
2259 fecp
->fec_imask
= FEC_ENET_MII
;
2260 fecp
->fec_mii_speed
= fep
->phy_speed
;
2263 static int __init
fec_enet_module_init(void)
2265 struct net_device
*dev
;
2268 for (i
= 0; (i
< FEC_MAX_PORTS
); i
++) {
2269 dev
= alloc_etherdev(sizeof(struct fec_enet_private
));
2272 err
= fec_enet_init(dev
);
2277 if (register_netdev(dev
) != 0) {
2278 /* XXX: missing cleanup here */
2286 module_init(fec_enet_module_init
);
2288 MODULE_LICENSE("GPL");