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 * Includes support for the following PHYs: QS6612, LXT970, LXT971/2.
13 * Right now, I am very wasteful with the buffers. I allocate memory
14 * pages and then divide them into 2K frame buffers. This way I know I
15 * have buffers large enough to hold one frame within one buffer descriptor.
16 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
17 * will be much more memory efficient and will easily handle lots of
20 * Much better multiple PHY support by Magnus Damm.
21 * Copyright (c) 2000 Ericsson Radio Systems AB.
23 * Make use of MII for PHY control configurable.
25 * Copyright (c) 2000-2002 Wolfgang Denk, DENX Software Engineering.
27 * Support for AMD AM79C874 added.
28 * Thomas Lange, thomas@corelatus.com
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/string.h>
34 #include <linux/ptrace.h>
35 #include <linux/errno.h>
36 #include <linux/ioport.h>
37 #include <linux/slab.h>
38 #include <linux/interrupt.h>
39 #include <linux/pci.h>
40 #include <linux/init.h>
41 #include <linux/delay.h>
42 #include <linux/netdevice.h>
43 #include <linux/etherdevice.h>
44 #include <linux/skbuff.h>
45 #include <linux/spinlock.h>
46 #include <linux/bitops.h>
47 #ifdef CONFIG_FEC_PACKETHOOK
48 #include <linux/pkthook.h>
51 #include <asm/8xx_immap.h>
52 #include <asm/pgtable.h>
53 #include <asm/mpc8xx.h>
55 #include <asm/uaccess.h>
56 #include <asm/commproc.h>
58 #ifdef CONFIG_USE_MDIO
59 /* Forward declarations of some structures to support different PHYs
64 void (*funct
)(uint mii_reg
, struct net_device
*dev
);
71 const phy_cmd_t
*config
;
72 const phy_cmd_t
*startup
;
73 const phy_cmd_t
*ack_int
;
74 const phy_cmd_t
*shutdown
;
76 #endif /* CONFIG_USE_MDIO */
78 /* The number of Tx and Rx buffers. These are allocated from the page
79 * pool. The code may assume these are power of two, so it is best
80 * to keep them that size.
81 * We don't need to allocate pages for the transmitter. We just use
82 * the skbuffer directly.
84 #ifdef CONFIG_ENET_BIG_BUFFERS
85 #define FEC_ENET_RX_PAGES 16
86 #define FEC_ENET_RX_FRSIZE 2048
87 #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
88 #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
89 #define TX_RING_SIZE 16 /* Must be power of two */
90 #define TX_RING_MOD_MASK 15 /* for this to work */
92 #define FEC_ENET_RX_PAGES 4
93 #define FEC_ENET_RX_FRSIZE 2048
94 #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
95 #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
96 #define TX_RING_SIZE 8 /* Must be power of two */
97 #define TX_RING_MOD_MASK 7 /* for this to work */
100 /* Interrupt events/masks.
102 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
103 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
104 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
105 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
106 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
107 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
108 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
109 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
110 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
111 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
115 #define FEC_ECNTRL_PINMUX 0x00000004
116 #define FEC_ECNTRL_ETHER_EN 0x00000002
117 #define FEC_ECNTRL_RESET 0x00000001
119 #define FEC_RCNTRL_BC_REJ 0x00000010
120 #define FEC_RCNTRL_PROM 0x00000008
121 #define FEC_RCNTRL_MII_MODE 0x00000004
122 #define FEC_RCNTRL_DRT 0x00000002
123 #define FEC_RCNTRL_LOOP 0x00000001
125 #define FEC_TCNTRL_FDEN 0x00000004
126 #define FEC_TCNTRL_HBC 0x00000002
127 #define FEC_TCNTRL_GTS 0x00000001
129 /* Delay to wait for FEC reset command to complete (in us)
131 #define FEC_RESET_DELAY 50
133 /* The FEC stores dest/src/type, data, and checksum for receive packets.
135 #define PKT_MAXBUF_SIZE 1518
136 #define PKT_MINBUF_SIZE 64
137 #define PKT_MAXBLR_SIZE 1520
139 /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
140 * tx_bd_base always point to the base of the buffer descriptors. The
141 * cur_rx and cur_tx point to the currently available buffer.
142 * The dirty_tx tracks the current buffer that is being sent by the
143 * controller. The cur_tx and dirty_tx are equal under both completely
144 * empty and completely full conditions. The empty/ready indicator in
145 * the buffer descriptor determines the actual condition.
147 struct fec_enet_private
{
148 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
149 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
153 /* CPM dual port RAM relative addresses.
155 cbd_t
*rx_bd_base
; /* Address of Rx and Tx buffers. */
157 cbd_t
*cur_rx
, *cur_tx
; /* The next free ring entry */
158 cbd_t
*dirty_tx
; /* The ring entries to be free()ed. */
160 /* Virtual addresses for the receive buffers because we can't
161 * do a __va() on them anymore.
163 unsigned char *rx_vaddr
[RX_RING_SIZE
];
165 struct net_device_stats stats
;
169 #ifdef CONFIG_USE_MDIO
175 struct work_struct phy_task
;
176 struct net_device
*dev
;
181 #endif /* CONFIG_USE_MDIO */
187 #ifdef CONFIG_FEC_PACKETHOOK
188 unsigned long ph_lock
;
189 fec_ph_func
*ph_rxhandler
;
190 fec_ph_func
*ph_txhandler
;
192 volatile __u32
*ph_regaddr
;
197 static int fec_enet_open(struct net_device
*dev
);
198 static int fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
199 #ifdef CONFIG_USE_MDIO
200 static void fec_enet_mii(struct net_device
*dev
);
201 #endif /* CONFIG_USE_MDIO */
202 static irqreturn_t
fec_enet_interrupt(int irq
, void * dev_id
);
203 #ifdef CONFIG_FEC_PACKETHOOK
204 static void fec_enet_tx(struct net_device
*dev
, __u32 regval
);
205 static void fec_enet_rx(struct net_device
*dev
, __u32 regval
);
207 static void fec_enet_tx(struct net_device
*dev
);
208 static void fec_enet_rx(struct net_device
*dev
);
210 static int fec_enet_close(struct net_device
*dev
);
211 static struct net_device_stats
*fec_enet_get_stats(struct net_device
*dev
);
212 static void set_multicast_list(struct net_device
*dev
);
213 static void fec_restart(struct net_device
*dev
, int duplex
);
214 static void fec_stop(struct net_device
*dev
);
215 static ushort my_enet_addr
[3];
217 #ifdef CONFIG_USE_MDIO
218 /* MII processing. We keep this as simple as possible. Requests are
219 * placed on the list (if there is room). When the request is finished
220 * by the MII, an optional function may be called.
222 typedef struct mii_list
{
224 void (*mii_func
)(uint val
, struct net_device
*dev
);
225 struct mii_list
*mii_next
;
229 mii_list_t mii_cmds
[NMII
];
230 mii_list_t
*mii_free
;
231 mii_list_t
*mii_head
;
232 mii_list_t
*mii_tail
;
234 static int mii_queue(struct net_device
*dev
, int request
,
235 void (*func
)(uint
, struct net_device
*));
237 /* Make MII read/write commands for the FEC.
239 #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
240 #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
243 #endif /* CONFIG_USE_MDIO */
245 /* Transmitter timeout.
247 #define TX_TIMEOUT (2*HZ)
249 #ifdef CONFIG_USE_MDIO
250 /* Register definitions for the PHY.
253 #define MII_REG_CR 0 /* Control Register */
254 #define MII_REG_SR 1 /* Status Register */
255 #define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
256 #define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
257 #define MII_REG_ANAR 4 /* A-N Advertisement Register */
258 #define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
259 #define MII_REG_ANER 6 /* A-N Expansion Register */
260 #define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
261 #define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
263 /* values for phy_status */
265 #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
266 #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
267 #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
268 #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
269 #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
270 #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
271 #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
273 #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
274 #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
275 #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
276 #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
277 #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
278 #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
279 #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
280 #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
281 #endif /* CONFIG_USE_MDIO */
283 #ifdef CONFIG_FEC_PACKETHOOK
285 fec_register_ph(struct net_device
*dev
, fec_ph_func
*rxfun
, fec_ph_func
*txfun
,
286 __u16 proto
, volatile __u32
*regaddr
, void *priv
)
288 struct fec_enet_private
*fep
;
293 if (test_and_set_bit(0, (void*)&fep
->ph_lock
) != 0) {
294 /* Someone is messing with the packet hook */
297 if (fep
->ph_rxhandler
!= NULL
|| fep
->ph_txhandler
!= NULL
) {
301 fep
->ph_rxhandler
= rxfun
;
302 fep
->ph_txhandler
= txfun
;
303 fep
->ph_proto
= proto
;
304 fep
->ph_regaddr
= regaddr
;
315 fec_unregister_ph(struct net_device
*dev
)
317 struct fec_enet_private
*fep
;
322 if (test_and_set_bit(0, (void*)&fep
->ph_lock
) != 0) {
323 /* Someone is messing with the packet hook */
327 fep
->ph_rxhandler
= fep
->ph_txhandler
= NULL
;
329 fep
->ph_regaddr
= NULL
;
337 EXPORT_SYMBOL(fec_register_ph
);
338 EXPORT_SYMBOL(fec_unregister_ph
);
340 #endif /* CONFIG_FEC_PACKETHOOK */
343 fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
345 struct fec_enet_private
*fep
;
346 volatile fec_t
*fecp
;
350 fecp
= (volatile fec_t
*)dev
->base_addr
;
353 /* Link is down or autonegotiation is in progress. */
357 /* Fill in a Tx ring entry */
360 #ifndef final_version
361 if (bdp
->cbd_sc
& BD_ENET_TX_READY
) {
362 /* Ooops. All transmit buffers are full. Bail out.
363 * This should not happen, since dev->tbusy should be set.
365 printk("%s: tx queue full!.\n", dev
->name
);
370 /* Clear all of the status flags.
372 bdp
->cbd_sc
&= ~BD_ENET_TX_STATS
;
374 /* Set buffer length and buffer pointer.
376 bdp
->cbd_bufaddr
= __pa(skb
->data
);
377 bdp
->cbd_datlen
= skb
->len
;
381 fep
->tx_skbuff
[fep
->skb_cur
] = skb
;
383 fep
->stats
.tx_bytes
+= skb
->len
;
384 fep
->skb_cur
= (fep
->skb_cur
+1) & TX_RING_MOD_MASK
;
386 /* Push the data cache so the CPM does not get stale memory
389 flush_dcache_range((unsigned long)skb
->data
,
390 (unsigned long)skb
->data
+ skb
->len
);
392 /* disable interrupts while triggering transmit */
393 spin_lock_irq(&fep
->lock
);
395 /* Send it on its way. Tell FEC its ready, interrupt when done,
396 * its the last BD of the frame, and to put the CRC on the end.
399 bdp
->cbd_sc
|= (BD_ENET_TX_READY
| BD_ENET_TX_INTR
400 | BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
402 dev
->trans_start
= jiffies
;
404 /* Trigger transmission start */
405 fecp
->fec_x_des_active
= 0x01000000;
407 /* If this was the last BD in the ring, start at the beginning again.
409 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
) {
410 bdp
= fep
->tx_bd_base
;
415 if (bdp
->cbd_sc
& BD_ENET_TX_READY
) {
416 netif_stop_queue(dev
);
420 fep
->cur_tx
= (cbd_t
*)bdp
;
422 spin_unlock_irq(&fep
->lock
);
428 fec_timeout(struct net_device
*dev
)
430 struct fec_enet_private
*fep
= dev
->priv
;
432 printk("%s: transmit timed out.\n", dev
->name
);
433 fep
->stats
.tx_errors
++;
434 #ifndef final_version
439 printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
440 (unsigned long)fep
->cur_tx
, fep
->tx_full
? " (full)" : "",
441 (unsigned long)fep
->dirty_tx
,
442 (unsigned long)fep
->cur_rx
);
444 bdp
= fep
->tx_bd_base
;
445 printk(" tx: %u buffers\n", TX_RING_SIZE
);
446 for (i
= 0 ; i
< TX_RING_SIZE
; i
++) {
447 printk(" %08x: %04x %04x %08x\n",
455 bdp
= fep
->rx_bd_base
;
456 printk(" rx: %lu buffers\n", RX_RING_SIZE
);
457 for (i
= 0 ; i
< RX_RING_SIZE
; i
++) {
458 printk(" %08x: %04x %04x %08x\n",
468 netif_wake_queue(dev
);
471 /* The interrupt handler.
472 * This is called from the MPC core interrupt.
475 fec_enet_interrupt(int irq
, void * dev_id
)
477 struct net_device
*dev
= dev_id
;
478 volatile fec_t
*fecp
;
480 #ifdef CONFIG_FEC_PACKETHOOK
481 struct fec_enet_private
*fep
= dev
->priv
;
484 if (fep
->ph_regaddr
) regval
= *fep
->ph_regaddr
;
486 fecp
= (volatile fec_t
*)dev
->base_addr
;
488 /* Get the interrupt events that caused us to be here.
490 while ((int_events
= fecp
->fec_ievent
) != 0) {
491 fecp
->fec_ievent
= int_events
;
492 if ((int_events
& (FEC_ENET_HBERR
| FEC_ENET_BABR
|
493 FEC_ENET_BABT
| FEC_ENET_EBERR
)) != 0) {
494 printk("FEC ERROR %x\n", int_events
);
497 /* Handle receive event in its own function.
499 if (int_events
& FEC_ENET_RXF
) {
500 #ifdef CONFIG_FEC_PACKETHOOK
501 fec_enet_rx(dev
, regval
);
507 /* Transmit OK, or non-fatal error. Update the buffer
508 descriptors. FEC handles all errors, we just discover
509 them as part of the transmit process.
511 if (int_events
& FEC_ENET_TXF
) {
512 #ifdef CONFIG_FEC_PACKETHOOK
513 fec_enet_tx(dev
, regval
);
519 if (int_events
& FEC_ENET_MII
) {
520 #ifdef CONFIG_USE_MDIO
523 printk("%s[%d] %s: unexpected FEC_ENET_MII event\n", __FILE__
,__LINE__
,__FUNCTION__
);
524 #endif /* CONFIG_USE_MDIO */
528 return IRQ_RETVAL(IRQ_HANDLED
);
533 #ifdef CONFIG_FEC_PACKETHOOK
534 fec_enet_tx(struct net_device
*dev
, __u32 regval
)
536 fec_enet_tx(struct net_device
*dev
)
539 struct fec_enet_private
*fep
;
544 /* lock while transmitting */
545 spin_lock(&fep
->lock
);
548 while ((bdp
->cbd_sc
&BD_ENET_TX_READY
) == 0) {
549 if (bdp
== fep
->cur_tx
&& fep
->tx_full
== 0) break;
551 skb
= fep
->tx_skbuff
[fep
->skb_dirty
];
552 /* Check for errors. */
553 if (bdp
->cbd_sc
& (BD_ENET_TX_HB
| BD_ENET_TX_LC
|
554 BD_ENET_TX_RL
| BD_ENET_TX_UN
|
556 fep
->stats
.tx_errors
++;
557 if (bdp
->cbd_sc
& BD_ENET_TX_HB
) /* No heartbeat */
558 fep
->stats
.tx_heartbeat_errors
++;
559 if (bdp
->cbd_sc
& BD_ENET_TX_LC
) /* Late collision */
560 fep
->stats
.tx_window_errors
++;
561 if (bdp
->cbd_sc
& BD_ENET_TX_RL
) /* Retrans limit */
562 fep
->stats
.tx_aborted_errors
++;
563 if (bdp
->cbd_sc
& BD_ENET_TX_UN
) /* Underrun */
564 fep
->stats
.tx_fifo_errors
++;
565 if (bdp
->cbd_sc
& BD_ENET_TX_CSL
) /* Carrier lost */
566 fep
->stats
.tx_carrier_errors
++;
568 #ifdef CONFIG_FEC_PACKETHOOK
569 /* Packet hook ... */
570 if (fep
->ph_txhandler
&&
571 ((struct ethhdr
*)skb
->data
)->h_proto
573 fep
->ph_txhandler((__u8
*)skb
->data
, skb
->len
,
574 regval
, fep
->ph_priv
);
577 fep
->stats
.tx_packets
++;
580 #ifndef final_version
581 if (bdp
->cbd_sc
& BD_ENET_TX_READY
)
582 printk("HEY! Enet xmit interrupt and TX_READY.\n");
584 /* Deferred means some collisions occurred during transmit,
585 * but we eventually sent the packet OK.
587 if (bdp
->cbd_sc
& BD_ENET_TX_DEF
)
588 fep
->stats
.collisions
++;
590 /* Free the sk buffer associated with this last transmit.
593 printk("TXI: %x %x %x\n", bdp
, skb
, fep
->skb_dirty
);
595 dev_kfree_skb_irq (skb
/*, FREE_WRITE*/);
596 fep
->tx_skbuff
[fep
->skb_dirty
] = NULL
;
597 fep
->skb_dirty
= (fep
->skb_dirty
+ 1) & TX_RING_MOD_MASK
;
599 /* Update pointer to next buffer descriptor to be transmitted.
601 if (bdp
->cbd_sc
& BD_ENET_TX_WRAP
)
602 bdp
= fep
->tx_bd_base
;
606 /* Since we have freed up a buffer, the ring is no longer
611 if (netif_queue_stopped(dev
))
612 netif_wake_queue(dev
);
614 #ifdef CONFIG_FEC_PACKETHOOK
615 /* Re-read register. Not exactly guaranteed to be correct,
617 if (fep
->ph_regaddr
) regval
= *fep
->ph_regaddr
;
620 fep
->dirty_tx
= (cbd_t
*)bdp
;
621 spin_unlock(&fep
->lock
);
625 /* During a receive, the cur_rx points to the current incoming buffer.
626 * When we update through the ring, if the next incoming buffer has
627 * not been given to the system, we just set the empty indicator,
628 * effectively tossing the packet.
631 #ifdef CONFIG_FEC_PACKETHOOK
632 fec_enet_rx(struct net_device
*dev
, __u32 regval
)
634 fec_enet_rx(struct net_device
*dev
)
637 struct fec_enet_private
*fep
;
638 volatile fec_t
*fecp
;
645 fecp
= (volatile fec_t
*)dev
->base_addr
;
647 /* First, grab all of the stats for the incoming packet.
648 * These get messed up if we get called due to a busy condition.
652 while (!(bdp
->cbd_sc
& BD_ENET_RX_EMPTY
)) {
654 #ifndef final_version
655 /* Since we have allocated space to hold a complete frame,
656 * the last indicator should be set.
658 if ((bdp
->cbd_sc
& BD_ENET_RX_LAST
) == 0)
659 printk("FEC ENET: rcv is not +last\n");
662 /* Check for errors. */
663 if (bdp
->cbd_sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
| BD_ENET_RX_NO
|
664 BD_ENET_RX_CR
| BD_ENET_RX_OV
)) {
665 fep
->stats
.rx_errors
++;
666 if (bdp
->cbd_sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
)) {
667 /* Frame too long or too short. */
668 fep
->stats
.rx_length_errors
++;
670 if (bdp
->cbd_sc
& BD_ENET_RX_NO
) /* Frame alignment */
671 fep
->stats
.rx_frame_errors
++;
672 if (bdp
->cbd_sc
& BD_ENET_RX_CR
) /* CRC Error */
673 fep
->stats
.rx_crc_errors
++;
674 if (bdp
->cbd_sc
& BD_ENET_RX_OV
) /* FIFO overrun */
675 fep
->stats
.rx_crc_errors
++;
678 /* Report late collisions as a frame error.
679 * On this error, the BD is closed, but we don't know what we
680 * have in the buffer. So, just drop this frame on the floor.
682 if (bdp
->cbd_sc
& BD_ENET_RX_CL
) {
683 fep
->stats
.rx_errors
++;
684 fep
->stats
.rx_frame_errors
++;
685 goto rx_processing_done
;
688 /* Process the incoming frame.
690 fep
->stats
.rx_packets
++;
691 pkt_len
= bdp
->cbd_datlen
;
692 fep
->stats
.rx_bytes
+= pkt_len
;
693 data
= fep
->rx_vaddr
[bdp
- fep
->rx_bd_base
];
695 #ifdef CONFIG_FEC_PACKETHOOK
696 /* Packet hook ... */
697 if (fep
->ph_rxhandler
) {
698 if (((struct ethhdr
*)data
)->h_proto
== fep
->ph_proto
) {
699 switch (fep
->ph_rxhandler(data
, pkt_len
, regval
,
702 goto rx_processing_done
;
707 fep
->stats
.rx_errors
++;
708 goto rx_processing_done
;
713 /* If it wasn't filtered - copy it to an sk buffer. */
716 /* This does 16 byte alignment, exactly what we need.
717 * The packet length includes FCS, but we don't want to
718 * include that when passing upstream as it messes up
719 * bridging applications.
721 skb
= dev_alloc_skb(pkt_len
-4);
724 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
725 fep
->stats
.rx_dropped
++;
727 skb_put(skb
,pkt_len
-4); /* Make room */
728 eth_copy_and_sum(skb
, data
, pkt_len
-4, 0);
729 skb
->protocol
=eth_type_trans(skb
,dev
);
734 /* Clear the status flags for this buffer.
736 bdp
->cbd_sc
&= ~BD_ENET_RX_STATS
;
738 /* Mark the buffer empty.
740 bdp
->cbd_sc
|= BD_ENET_RX_EMPTY
;
742 /* Update BD pointer to next entry.
744 if (bdp
->cbd_sc
& BD_ENET_RX_WRAP
)
745 bdp
= fep
->rx_bd_base
;
750 /* Doing this here will keep the FEC running while we process
751 * incoming frames. On a heavily loaded network, we should be
752 * able to keep up at the expense of system resources.
754 fecp
->fec_r_des_active
= 0x01000000;
756 #ifdef CONFIG_FEC_PACKETHOOK
757 /* Re-read register. Not exactly guaranteed to be correct,
759 if (fep
->ph_regaddr
) regval
= *fep
->ph_regaddr
;
761 } /* while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) */
762 fep
->cur_rx
= (cbd_t
*)bdp
;
765 /* Doing this here will allow us to process all frames in the
766 * ring before the FEC is allowed to put more there. On a heavily
767 * loaded network, some frames may be lost. Unfortunately, this
768 * increases the interrupt overhead since we can potentially work
769 * our way back to the interrupt return only to come right back
772 fecp
->fec_r_des_active
= 0x01000000;
777 #ifdef CONFIG_USE_MDIO
779 fec_enet_mii(struct net_device
*dev
)
781 struct fec_enet_private
*fep
;
786 fep
= (struct fec_enet_private
*)dev
->priv
;
787 ep
= &(((immap_t
*)IMAP_ADDR
)->im_cpm
.cp_fec
);
788 mii_reg
= ep
->fec_mii_data
;
790 if ((mip
= mii_head
) == NULL
) {
791 printk("MII and no head!\n");
795 if (mip
->mii_func
!= NULL
)
796 (*(mip
->mii_func
))(mii_reg
, dev
);
798 mii_head
= mip
->mii_next
;
799 mip
->mii_next
= mii_free
;
802 if ((mip
= mii_head
) != NULL
) {
803 ep
->fec_mii_data
= mip
->mii_regval
;
809 mii_queue(struct net_device
*dev
, int regval
, void (*func
)(uint
, struct net_device
*))
811 struct fec_enet_private
*fep
;
816 /* Add PHY address to register command.
819 regval
|= fep
->phy_addr
<< 23;
823 /* lock while modifying mii_list */
824 spin_lock_irqsave(&fep
->lock
, flags
);
826 if ((mip
= mii_free
) != NULL
) {
827 mii_free
= mip
->mii_next
;
828 mip
->mii_regval
= regval
;
829 mip
->mii_func
= func
;
830 mip
->mii_next
= NULL
;
832 mii_tail
->mii_next
= mip
;
835 mii_head
= mii_tail
= mip
;
836 (&(((immap_t
*)IMAP_ADDR
)->im_cpm
.cp_fec
))->fec_mii_data
= regval
;
842 spin_unlock_irqrestore(&fep
->lock
, flags
);
847 static void mii_do_cmd(struct net_device
*dev
, const phy_cmd_t
*c
)
854 for(k
= 0; (c
+k
)->mii_data
!= mk_mii_end
; k
++)
855 mii_queue(dev
, (c
+k
)->mii_data
, (c
+k
)->funct
);
858 static void mii_parse_sr(uint mii_reg
, struct net_device
*dev
)
860 struct fec_enet_private
*fep
= dev
->priv
;
861 volatile uint
*s
= &(fep
->phy_status
);
863 *s
&= ~(PHY_STAT_LINK
| PHY_STAT_FAULT
| PHY_STAT_ANC
);
865 if (mii_reg
& 0x0004)
867 if (mii_reg
& 0x0010)
868 *s
|= PHY_STAT_FAULT
;
869 if (mii_reg
& 0x0020)
872 fep
->link
= (*s
& PHY_STAT_LINK
) ? 1 : 0;
875 static void mii_parse_cr(uint mii_reg
, struct net_device
*dev
)
877 struct fec_enet_private
*fep
= dev
->priv
;
878 volatile uint
*s
= &(fep
->phy_status
);
880 *s
&= ~(PHY_CONF_ANE
| PHY_CONF_LOOP
);
882 if (mii_reg
& 0x1000)
884 if (mii_reg
& 0x4000)
888 static void mii_parse_anar(uint mii_reg
, struct net_device
*dev
)
890 struct fec_enet_private
*fep
= dev
->priv
;
891 volatile uint
*s
= &(fep
->phy_status
);
893 *s
&= ~(PHY_CONF_SPMASK
);
895 if (mii_reg
& 0x0020)
896 *s
|= PHY_CONF_10HDX
;
897 if (mii_reg
& 0x0040)
898 *s
|= PHY_CONF_10FDX
;
899 if (mii_reg
& 0x0080)
900 *s
|= PHY_CONF_100HDX
;
901 if (mii_reg
& 0x00100)
902 *s
|= PHY_CONF_100FDX
;
905 static void mii_disp_reg(uint mii_reg
, struct net_device
*dev
)
907 printk("reg %u = 0x%04x\n", (mii_reg
>> 18) & 0x1f, mii_reg
& 0xffff);
911 /* ------------------------------------------------------------------------- */
912 /* The Level one LXT970 is used by many boards */
914 #ifdef CONFIG_FEC_LXT970
916 #define MII_LXT970_MIRROR 16 /* Mirror register */
917 #define MII_LXT970_IER 17 /* Interrupt Enable Register */
918 #define MII_LXT970_ISR 18 /* Interrupt Status Register */
919 #define MII_LXT970_CONFIG 19 /* Configuration Register */
920 #define MII_LXT970_CSR 20 /* Chip Status Register */
922 static void mii_parse_lxt970_csr(uint mii_reg
, struct net_device
*dev
)
924 struct fec_enet_private
*fep
= dev
->priv
;
925 volatile uint
*s
= &(fep
->phy_status
);
927 *s
&= ~(PHY_STAT_SPMASK
);
929 if (mii_reg
& 0x0800) {
930 if (mii_reg
& 0x1000)
931 *s
|= PHY_STAT_100FDX
;
933 *s
|= PHY_STAT_100HDX
;
936 if (mii_reg
& 0x1000)
937 *s
|= PHY_STAT_10FDX
;
939 *s
|= PHY_STAT_10HDX
;
943 static phy_info_t phy_info_lxt970
= {
947 (const phy_cmd_t
[]) { /* config */
949 // { mk_mii_write(MII_REG_ANAR, 0x0021), NULL },
951 /* Set default operation of 100-TX....for some reason
952 * some of these bits are set on power up, which is wrong.
954 { mk_mii_write(MII_LXT970_CONFIG
, 0), NULL
},
956 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
957 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
960 (const phy_cmd_t
[]) { /* startup - enable interrupts */
961 { mk_mii_write(MII_LXT970_IER
, 0x0002), NULL
},
962 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
965 (const phy_cmd_t
[]) { /* ack_int */
966 /* read SR and ISR to acknowledge */
968 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
969 { mk_mii_read(MII_LXT970_ISR
), NULL
},
971 /* find out the current status */
973 { mk_mii_read(MII_LXT970_CSR
), mii_parse_lxt970_csr
},
976 (const phy_cmd_t
[]) { /* shutdown - disable interrupts */
977 { mk_mii_write(MII_LXT970_IER
, 0x0000), NULL
},
982 #endif /* CONFIG_FEC_LXT970 */
984 /* ------------------------------------------------------------------------- */
985 /* The Level one LXT971 is used on some of my custom boards */
987 #ifdef CONFIG_FEC_LXT971
989 /* register definitions for the 971 */
991 #define MII_LXT971_PCR 16 /* Port Control Register */
992 #define MII_LXT971_SR2 17 /* Status Register 2 */
993 #define MII_LXT971_IER 18 /* Interrupt Enable Register */
994 #define MII_LXT971_ISR 19 /* Interrupt Status Register */
995 #define MII_LXT971_LCR 20 /* LED Control Register */
996 #define MII_LXT971_TCR 30 /* Transmit Control Register */
999 * I had some nice ideas of running the MDIO faster...
1000 * The 971 should support 8MHz and I tried it, but things acted really
1001 * weird, so 2.5 MHz ought to be enough for anyone...
1004 static void mii_parse_lxt971_sr2(uint mii_reg
, struct net_device
*dev
)
1006 struct fec_enet_private
*fep
= dev
->priv
;
1007 volatile uint
*s
= &(fep
->phy_status
);
1009 *s
&= ~(PHY_STAT_SPMASK
);
1011 if (mii_reg
& 0x4000) {
1012 if (mii_reg
& 0x0200)
1013 *s
|= PHY_STAT_100FDX
;
1015 *s
|= PHY_STAT_100HDX
;
1018 if (mii_reg
& 0x0200)
1019 *s
|= PHY_STAT_10FDX
;
1021 *s
|= PHY_STAT_10HDX
;
1023 if (mii_reg
& 0x0008)
1024 *s
|= PHY_STAT_FAULT
;
1027 static phy_info_t phy_info_lxt971
= {
1031 (const phy_cmd_t
[]) { /* config */
1032 // { mk_mii_write(MII_REG_ANAR, 0x021), NULL }, /* 10 Mbps, HD */
1033 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1034 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1037 (const phy_cmd_t
[]) { /* startup - enable interrupts */
1038 { mk_mii_write(MII_LXT971_IER
, 0x00f2), NULL
},
1039 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1041 /* Somehow does the 971 tell me that the link is down
1042 * the first read after power-up.
1043 * read here to get a valid value in ack_int */
1045 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1048 (const phy_cmd_t
[]) { /* ack_int */
1049 /* find out the current status */
1051 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1052 { mk_mii_read(MII_LXT971_SR2
), mii_parse_lxt971_sr2
},
1054 /* we only need to read ISR to acknowledge */
1056 { mk_mii_read(MII_LXT971_ISR
), NULL
},
1059 (const phy_cmd_t
[]) { /* shutdown - disable interrupts */
1060 { mk_mii_write(MII_LXT971_IER
, 0x0000), NULL
},
1065 #endif /* CONFIG_FEC_LXT970 */
1068 /* ------------------------------------------------------------------------- */
1069 /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
1071 #ifdef CONFIG_FEC_QS6612
1073 /* register definitions */
1075 #define MII_QS6612_MCR 17 /* Mode Control Register */
1076 #define MII_QS6612_FTR 27 /* Factory Test Register */
1077 #define MII_QS6612_MCO 28 /* Misc. Control Register */
1078 #define MII_QS6612_ISR 29 /* Interrupt Source Register */
1079 #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
1080 #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
1082 static void mii_parse_qs6612_pcr(uint mii_reg
, struct net_device
*dev
)
1084 struct fec_enet_private
*fep
= dev
->priv
;
1085 volatile uint
*s
= &(fep
->phy_status
);
1087 *s
&= ~(PHY_STAT_SPMASK
);
1089 switch((mii_reg
>> 2) & 7) {
1090 case 1: *s
|= PHY_STAT_10HDX
; break;
1091 case 2: *s
|= PHY_STAT_100HDX
; break;
1092 case 5: *s
|= PHY_STAT_10FDX
; break;
1093 case 6: *s
|= PHY_STAT_100FDX
; break;
1097 static phy_info_t phy_info_qs6612
= {
1101 (const phy_cmd_t
[]) { /* config */
1102 // { mk_mii_write(MII_REG_ANAR, 0x061), NULL }, /* 10 Mbps */
1104 /* The PHY powers up isolated on the RPX,
1105 * so send a command to allow operation.
1108 { mk_mii_write(MII_QS6612_PCR
, 0x0dc0), NULL
},
1110 /* parse cr and anar to get some info */
1112 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1113 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1116 (const phy_cmd_t
[]) { /* startup - enable interrupts */
1117 { mk_mii_write(MII_QS6612_IMR
, 0x003a), NULL
},
1118 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1121 (const phy_cmd_t
[]) { /* ack_int */
1123 /* we need to read ISR, SR and ANER to acknowledge */
1125 { mk_mii_read(MII_QS6612_ISR
), NULL
},
1126 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1127 { mk_mii_read(MII_REG_ANER
), NULL
},
1129 /* read pcr to get info */
1131 { mk_mii_read(MII_QS6612_PCR
), mii_parse_qs6612_pcr
},
1134 (const phy_cmd_t
[]) { /* shutdown - disable interrupts */
1135 { mk_mii_write(MII_QS6612_IMR
, 0x0000), NULL
},
1140 #endif /* CONFIG_FEC_QS6612 */
1142 /* ------------------------------------------------------------------------- */
1143 /* The Advanced Micro Devices AM79C874 is used on the ICU862 */
1145 #ifdef CONFIG_FEC_AM79C874
1147 /* register definitions for the 79C874 */
1149 #define MII_AM79C874_MFR 16 /* Miscellaneous Features Register */
1150 #define MII_AM79C874_ICSR 17 /* Interrupt Control/Status Register */
1151 #define MII_AM79C874_DR 18 /* Diagnostic Register */
1152 #define MII_AM79C874_PMLR 19 /* Power Management & Loopback Register */
1153 #define MII_AM79C874_MCR 21 /* Mode Control Register */
1154 #define MII_AM79C874_DC 23 /* Disconnect Counter */
1155 #define MII_AM79C874_REC 24 /* Receiver Error Counter */
1157 static void mii_parse_amd79c874_dr(uint mii_reg
, struct net_device
*dev
, uint data
)
1159 volatile struct fec_enet_private
*fep
= dev
->priv
;
1160 uint s
= fep
->phy_status
;
1162 s
&= ~(PHY_STAT_SPMASK
);
1164 /* Register 18: Bit 10 is data rate, 11 is Duplex */
1165 switch ((mii_reg
>> 10) & 3) {
1166 case 0: s
|= PHY_STAT_10HDX
; break;
1167 case 1: s
|= PHY_STAT_100HDX
; break;
1168 case 2: s
|= PHY_STAT_10FDX
; break;
1169 case 3: s
|= PHY_STAT_100FDX
; break;
1172 fep
->phy_status
= s
;
1175 static phy_info_t phy_info_amd79c874
= {
1179 (const phy_cmd_t
[]) { /* config */
1180 // { mk_mii_write(MII_REG_ANAR, 0x021), NULL }, /* 10 Mbps, HD */
1181 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1182 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1185 (const phy_cmd_t
[]) { /* startup - enable interrupts */
1186 { mk_mii_write(MII_AM79C874_ICSR
, 0xff00), NULL
},
1187 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1190 (const phy_cmd_t
[]) { /* ack_int */
1191 /* find out the current status */
1193 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1194 { mk_mii_read(MII_AM79C874_DR
), mii_parse_amd79c874_dr
},
1196 /* we only need to read ICSR to acknowledge */
1198 { mk_mii_read(MII_AM79C874_ICSR
), NULL
},
1201 (const phy_cmd_t
[]) { /* shutdown - disable interrupts */
1202 { mk_mii_write(MII_AM79C874_ICSR
, 0x0000), NULL
},
1207 #endif /* CONFIG_FEC_AM79C874 */
1209 static phy_info_t
*phy_info
[] = {
1211 #ifdef CONFIG_FEC_LXT970
1213 #endif /* CONFIG_FEC_LXT970 */
1215 #ifdef CONFIG_FEC_LXT971
1217 #endif /* CONFIG_FEC_LXT971 */
1219 #ifdef CONFIG_FEC_QS6612
1221 #endif /* CONFIG_FEC_QS6612 */
1223 #ifdef CONFIG_FEC_AM79C874
1224 &phy_info_amd79c874
,
1225 #endif /* CONFIG_FEC_AM79C874 */
1230 static void mii_display_status(struct net_device
*dev
)
1232 struct fec_enet_private
*fep
= dev
->priv
;
1233 volatile uint
*s
= &(fep
->phy_status
);
1235 if (!fep
->link
&& !fep
->old_link
) {
1236 /* Link is still down - don't print anything */
1240 printk("%s: status: ", dev
->name
);
1243 printk("link down");
1247 switch(*s
& PHY_STAT_SPMASK
) {
1248 case PHY_STAT_100FDX
: printk(", 100 Mbps Full Duplex"); break;
1249 case PHY_STAT_100HDX
: printk(", 100 Mbps Half Duplex"); break;
1250 case PHY_STAT_10FDX
: printk(", 10 Mbps Full Duplex"); break;
1251 case PHY_STAT_10HDX
: printk(", 10 Mbps Half Duplex"); break;
1253 printk(", Unknown speed/duplex");
1256 if (*s
& PHY_STAT_ANC
)
1257 printk(", auto-negotiation complete");
1260 if (*s
& PHY_STAT_FAULT
)
1261 printk(", remote fault");
1266 static void mii_display_config(struct work_struct
*work
)
1268 struct fec_enet_private
*fep
=
1269 container_of(work
, struct fec_enet_private
, phy_task
);
1270 struct net_device
*dev
= fep
->dev
;
1271 volatile uint
*s
= &(fep
->phy_status
);
1273 printk("%s: config: auto-negotiation ", dev
->name
);
1275 if (*s
& PHY_CONF_ANE
)
1280 if (*s
& PHY_CONF_100FDX
)
1282 if (*s
& PHY_CONF_100HDX
)
1284 if (*s
& PHY_CONF_10FDX
)
1286 if (*s
& PHY_CONF_10HDX
)
1288 if (!(*s
& PHY_CONF_SPMASK
))
1289 printk(", No speed/duplex selected?");
1291 if (*s
& PHY_CONF_LOOP
)
1292 printk(", loopback enabled");
1296 fep
->sequence_done
= 1;
1299 static void mii_relink(struct work_struct
*work
)
1301 struct fec_enet_private
*fep
=
1302 container_of(work
, struct fec_enet_private
, phy_task
);
1303 struct net_device
*dev
= fep
->dev
;
1306 fep
->link
= (fep
->phy_status
& PHY_STAT_LINK
) ? 1 : 0;
1307 mii_display_status(dev
);
1308 fep
->old_link
= fep
->link
;
1313 & (PHY_STAT_100FDX
| PHY_STAT_10FDX
))
1315 fec_restart(dev
, duplex
);
1321 enable_irq(fep
->mii_irq
);
1326 static void mii_queue_relink(uint mii_reg
, struct net_device
*dev
)
1328 struct fec_enet_private
*fep
= dev
->priv
;
1331 INIT_WORK(&fep
->phy_task
, mii_relink
);
1332 schedule_work(&fep
->phy_task
);
1335 static void mii_queue_config(uint mii_reg
, struct net_device
*dev
)
1337 struct fec_enet_private
*fep
= dev
->priv
;
1340 INIT_WORK(&fep
->phy_task
, mii_display_config
);
1341 schedule_work(&fep
->phy_task
);
1346 phy_cmd_t phy_cmd_relink
[] = { { mk_mii_read(MII_REG_CR
), mii_queue_relink
},
1348 phy_cmd_t phy_cmd_config
[] = { { mk_mii_read(MII_REG_CR
), mii_queue_config
},
1353 /* Read remainder of PHY ID.
1356 mii_discover_phy3(uint mii_reg
, struct net_device
*dev
)
1358 struct fec_enet_private
*fep
;
1362 fep
->phy_id
|= (mii_reg
& 0xffff);
1364 for(i
= 0; phy_info
[i
]; i
++)
1365 if(phy_info
[i
]->id
== (fep
->phy_id
>> 4))
1369 panic("%s: PHY id 0x%08x is not supported!\n",
1370 dev
->name
, fep
->phy_id
);
1372 fep
->phy
= phy_info
[i
];
1373 fep
->phy_id_done
= 1;
1375 printk("%s: Phy @ 0x%x, type %s (0x%08x)\n",
1376 dev
->name
, fep
->phy_addr
, fep
->phy
->name
, fep
->phy_id
);
1379 /* Scan all of the MII PHY addresses looking for someone to respond
1380 * with a valid ID. This usually happens quickly.
1383 mii_discover_phy(uint mii_reg
, struct net_device
*dev
)
1385 struct fec_enet_private
*fep
;
1390 if ((phytype
= (mii_reg
& 0xffff)) != 0xffff) {
1392 /* Got first part of ID, now get remainder.
1394 fep
->phy_id
= phytype
<< 16;
1395 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR2
), mii_discover_phy3
);
1398 if (fep
->phy_addr
< 32) {
1399 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
),
1402 printk("fec: No PHY device found.\n");
1406 #endif /* CONFIG_USE_MDIO */
1408 /* This interrupt occurs when the PHY detects a link change.
1411 #ifdef CONFIG_RPXCLASSIC
1412 void mii_link_interrupt(void *dev_id
)
1414 irqreturn_t
mii_link_interrupt(int irq
, void * dev_id
)
1417 #ifdef CONFIG_USE_MDIO
1418 struct net_device
*dev
= dev_id
;
1419 struct fec_enet_private
*fep
= dev
->priv
;
1420 volatile immap_t
*immap
= (immap_t
*)IMAP_ADDR
;
1421 volatile fec_t
*fecp
= &(immap
->im_cpm
.cp_fec
);
1422 unsigned int ecntrl
= fecp
->fec_ecntrl
;
1424 /* We need the FEC enabled to access the MII
1426 if ((ecntrl
& FEC_ECNTRL_ETHER_EN
) == 0) {
1427 fecp
->fec_ecntrl
|= FEC_ECNTRL_ETHER_EN
;
1429 #endif /* CONFIG_USE_MDIO */
1432 disable_irq(fep
->mii_irq
); /* disable now, enable later */
1436 #ifdef CONFIG_USE_MDIO
1437 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1438 mii_do_cmd(dev
, phy_cmd_relink
); /* restart and display status */
1440 if ((ecntrl
& FEC_ECNTRL_ETHER_EN
) == 0) {
1441 fecp
->fec_ecntrl
= ecntrl
; /* restore old settings */
1444 printk("%s[%d] %s: unexpected Link interrupt\n", __FILE__
,__LINE__
,__FUNCTION__
);
1445 #endif /* CONFIG_USE_MDIO */
1447 #ifndef CONFIG_RPXCLASSIC
1448 return IRQ_RETVAL(IRQ_HANDLED
);
1449 #endif /* CONFIG_RPXCLASSIC */
1453 fec_enet_open(struct net_device
*dev
)
1455 struct fec_enet_private
*fep
= dev
->priv
;
1457 /* I should reset the ring buffers here, but I don't yet know
1458 * a simple way to do that.
1461 #ifdef CONFIG_USE_MDIO
1462 fep
->sequence_done
= 0;
1466 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1467 mii_do_cmd(dev
, fep
->phy
->config
);
1468 mii_do_cmd(dev
, phy_cmd_config
); /* display configuration */
1469 while(!fep
->sequence_done
)
1472 mii_do_cmd(dev
, fep
->phy
->startup
);
1473 netif_start_queue(dev
);
1474 return 0; /* Success */
1476 return -ENODEV
; /* No PHY we understand */
1479 netif_start_queue(dev
);
1480 return 0; /* Success */
1481 #endif /* CONFIG_USE_MDIO */
1486 fec_enet_close(struct net_device
*dev
)
1488 /* Don't know what to do yet.
1490 netif_stop_queue(dev
);
1496 static struct net_device_stats
*fec_enet_get_stats(struct net_device
*dev
)
1498 struct fec_enet_private
*fep
= (struct fec_enet_private
*)dev
->priv
;
1503 /* Set or clear the multicast filter for this adaptor.
1504 * Skeleton taken from sunlance driver.
1505 * The CPM Ethernet implementation allows Multicast as well as individual
1506 * MAC address filtering. Some of the drivers check to make sure it is
1507 * a group multicast address, and discard those that are not. I guess I
1508 * will do the same for now, but just remove the test if you want
1509 * individual filtering as well (do the upper net layers want or support
1510 * this kind of feature?).
1513 static void set_multicast_list(struct net_device
*dev
)
1515 struct fec_enet_private
*fep
;
1518 fep
= (struct fec_enet_private
*)dev
->priv
;
1519 ep
= &(((immap_t
*)IMAP_ADDR
)->im_cpm
.cp_fec
);
1521 if (dev
->flags
&IFF_PROMISC
) {
1523 /* Log any net taps. */
1524 printk("%s: Promiscuous mode enabled.\n", dev
->name
);
1525 ep
->fec_r_cntrl
|= FEC_RCNTRL_PROM
;
1528 ep
->fec_r_cntrl
&= ~FEC_RCNTRL_PROM
;
1530 if (dev
->flags
& IFF_ALLMULTI
) {
1531 /* Catch all multicast addresses, so set the
1532 * filter to all 1's.
1534 ep
->fec_hash_table_high
= 0xffffffff;
1535 ep
->fec_hash_table_low
= 0xffffffff;
1539 /* Clear filter and add the addresses in the list.
1548 for (i
=0; i
<dev
->mc_count
; i
++) {
1550 /* Only support group multicast for now.
1552 if (!(dmi
->dmi_addr
[0] & 1))
1555 /* The address in dmi_addr is LSB first,
1556 * and taddr is MSB first. We have to
1557 * copy bytes MSB first from dmi_addr.
1559 mcptr
= (u_char
*)dmi
->dmi_addr
+ 5;
1560 tdptr
= (u_char
*)&ep
->sen_taddrh
;
1562 *tdptr
++ = *mcptr
--;
1564 /* Ask CPM to run CRC and set bit in
1567 cpmp
->cp_cpcr
= mk_cr_cmd(CPM_CR_CH_SCC1
, CPM_CR_SET_GADDR
) | CPM_CR_FLG
;
1568 /* this delay is necessary here -- Cort */
1570 while (cpmp
->cp_cpcr
& CPM_CR_FLG
);
1577 /* Initialize the FEC Ethernet on 860T.
1579 static int __init
fec_enet_init(void)
1581 struct net_device
*dev
;
1582 struct fec_enet_private
*fep
;
1584 unsigned char *eap
, *iap
, *ba
;
1585 dma_addr_t mem_addr
;
1586 volatile cbd_t
*bdp
;
1588 volatile immap_t
*immap
;
1589 volatile fec_t
*fecp
;
1591 #ifdef CONFIG_SCC_ENET
1592 unsigned char tmpaddr
[6];
1595 immap
= (immap_t
*)IMAP_ADDR
; /* pointer to internal registers */
1599 dev
= alloc_etherdev(sizeof(*fep
));
1605 fecp
= &(immap
->im_cpm
.cp_fec
);
1607 /* Whack a reset. We should wait for this.
1609 fecp
->fec_ecntrl
= FEC_ECNTRL_PINMUX
| FEC_ECNTRL_RESET
;
1611 (fecp
->fec_ecntrl
& FEC_ECNTRL_RESET
) && (i
< FEC_RESET_DELAY
);
1615 if (i
== FEC_RESET_DELAY
) {
1616 printk ("FEC Reset timeout!\n");
1619 /* Set the Ethernet address. If using multiple Enets on the 8xx,
1620 * this needs some work to get unique addresses.
1622 eap
= (unsigned char *)my_enet_addr
;
1623 iap
= bd
->bi_enetaddr
;
1625 #ifdef CONFIG_SCC_ENET
1627 * If a board has Ethernet configured both on a SCC and the
1628 * FEC, it needs (at least) 2 MAC addresses (we know that Sun
1629 * disagrees, but anyway). For the FEC port, we create
1630 * another address by setting one of the address bits above
1631 * something that would have (up to now) been allocated.
1634 tmpaddr
[i
] = *iap
++;
1639 for (i
=0; i
<6; i
++) {
1640 dev
->dev_addr
[i
] = *eap
++ = *iap
++;
1643 /* Allocate memory for buffer descriptors.
1645 if (((RX_RING_SIZE
+ TX_RING_SIZE
) * sizeof(cbd_t
)) > PAGE_SIZE
) {
1646 printk("FEC init error. Need more space.\n");
1647 printk("FEC initialization failed.\n");
1650 cbd_base
= (cbd_t
*)dma_alloc_coherent(dev
->class_dev
.dev
, PAGE_SIZE
,
1651 &mem_addr
, GFP_KERNEL
);
1653 /* Set receive and transmit descriptor base.
1655 fep
->rx_bd_base
= cbd_base
;
1656 fep
->tx_bd_base
= cbd_base
+ RX_RING_SIZE
;
1658 fep
->skb_cur
= fep
->skb_dirty
= 0;
1660 /* Initialize the receive buffer descriptors.
1662 bdp
= fep
->rx_bd_base
;
1664 for (i
=0; i
<FEC_ENET_RX_PAGES
; i
++) {
1668 ba
= (unsigned char *)dma_alloc_coherent(dev
->class_dev
.dev
,
1672 /* BUG: no check for failure */
1674 /* Initialize the BD for every fragment in the page.
1676 for (j
=0; j
<FEC_ENET_RX_FRPPG
; j
++) {
1677 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
1678 bdp
->cbd_bufaddr
= mem_addr
;
1679 fep
->rx_vaddr
[k
++] = ba
;
1680 mem_addr
+= FEC_ENET_RX_FRSIZE
;
1681 ba
+= FEC_ENET_RX_FRSIZE
;
1686 /* Set the last buffer to wrap.
1689 bdp
->cbd_sc
|= BD_SC_WRAP
;
1691 #ifdef CONFIG_FEC_PACKETHOOK
1693 fep
->ph_rxhandler
= fep
->ph_txhandler
= NULL
;
1695 fep
->ph_regaddr
= NULL
;
1696 fep
->ph_priv
= NULL
;
1699 /* Install our interrupt handler.
1701 if (request_irq(FEC_INTERRUPT
, fec_enet_interrupt
, 0, "fec", dev
) != 0)
1702 panic("Could not allocate FEC IRQ!");
1704 #ifdef CONFIG_RPXCLASSIC
1705 /* Make Port C, bit 15 an input that causes interrupts.
1707 immap
->im_ioport
.iop_pcpar
&= ~0x0001;
1708 immap
->im_ioport
.iop_pcdir
&= ~0x0001;
1709 immap
->im_ioport
.iop_pcso
&= ~0x0001;
1710 immap
->im_ioport
.iop_pcint
|= 0x0001;
1711 cpm_install_handler(CPMVEC_PIO_PC15
, mii_link_interrupt
, dev
);
1713 /* Make LEDS reflect Link status.
1715 *((uint
*) RPX_CSR_ADDR
) &= ~BCSR2_FETHLEDMODE
;
1718 #ifdef PHY_INTERRUPT
1719 ((immap_t
*)IMAP_ADDR
)->im_siu_conf
.sc_siel
|=
1720 (0x80000000 >> PHY_INTERRUPT
);
1722 if (request_irq(PHY_INTERRUPT
, mii_link_interrupt
, 0, "mii", dev
) != 0)
1723 panic("Could not allocate MII IRQ!");
1726 dev
->base_addr
= (unsigned long)fecp
;
1728 /* The FEC Ethernet specific entries in the device structure. */
1729 dev
->open
= fec_enet_open
;
1730 dev
->hard_start_xmit
= fec_enet_start_xmit
;
1731 dev
->tx_timeout
= fec_timeout
;
1732 dev
->watchdog_timeo
= TX_TIMEOUT
;
1733 dev
->stop
= fec_enet_close
;
1734 dev
->get_stats
= fec_enet_get_stats
;
1735 dev
->set_multicast_list
= set_multicast_list
;
1737 #ifdef CONFIG_USE_MDIO
1738 for (i
=0; i
<NMII
-1; i
++)
1739 mii_cmds
[i
].mii_next
= &mii_cmds
[i
+1];
1740 mii_free
= mii_cmds
;
1741 #endif /* CONFIG_USE_MDIO */
1743 /* Configure all of port D for MII.
1745 immap
->im_ioport
.iop_pdpar
= 0x1fff;
1747 /* Bits moved from Rev. D onward.
1749 if ((mfspr(SPRN_IMMR
) & 0xffff) < 0x0501)
1750 immap
->im_ioport
.iop_pddir
= 0x1c58; /* Pre rev. D */
1752 immap
->im_ioport
.iop_pddir
= 0x1fff; /* Rev. D and later */
1754 #ifdef CONFIG_USE_MDIO
1755 /* Set MII speed to 2.5 MHz
1757 fecp
->fec_mii_speed
= fep
->phy_speed
=
1758 (( (bd
->bi_intfreq
+ 500000) / 2500000 / 2 ) & 0x3F ) << 1;
1760 fecp
->fec_mii_speed
= 0; /* turn off MDIO */
1761 #endif /* CONFIG_USE_MDIO */
1763 err
= register_netdev(dev
);
1769 printk ("%s: FEC ENET Version 0.2, FEC irq %d"
1770 #ifdef PHY_INTERRUPT
1774 dev
->name
, FEC_INTERRUPT
1775 #ifdef PHY_INTERRUPT
1780 printk("%02x%c", dev
->dev_addr
[i
], (i
==5) ? '\n' : ':');
1782 #ifdef CONFIG_USE_MDIO /* start in full duplex mode, and negotiate speed */
1783 fec_restart (dev
, 1);
1784 #else /* always use half duplex mode only */
1785 fec_restart (dev
, 0);
1788 #ifdef CONFIG_USE_MDIO
1789 /* Queue up command to detect the PHY and initialize the
1790 * remainder of the interface.
1792 fep
->phy_id_done
= 0;
1794 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
), mii_discover_phy
);
1795 #endif /* CONFIG_USE_MDIO */
1799 module_init(fec_enet_init
);
1801 /* This function is called to start or restart the FEC during a link
1802 * change. This only happens when switching between half and full
1806 fec_restart(struct net_device
*dev
, int duplex
)
1808 struct fec_enet_private
*fep
;
1810 volatile cbd_t
*bdp
;
1811 volatile immap_t
*immap
;
1812 volatile fec_t
*fecp
;
1814 immap
= (immap_t
*)IMAP_ADDR
; /* pointer to internal registers */
1816 fecp
= &(immap
->im_cpm
.cp_fec
);
1820 /* Whack a reset. We should wait for this.
1822 fecp
->fec_ecntrl
= FEC_ECNTRL_PINMUX
| FEC_ECNTRL_RESET
;
1824 (fecp
->fec_ecntrl
& FEC_ECNTRL_RESET
) && (i
< FEC_RESET_DELAY
);
1828 if (i
== FEC_RESET_DELAY
) {
1829 printk ("FEC Reset timeout!\n");
1832 /* Set station address.
1834 fecp
->fec_addr_low
= (my_enet_addr
[0] << 16) | my_enet_addr
[1];
1835 fecp
->fec_addr_high
= my_enet_addr
[2];
1837 /* Reset all multicast.
1839 fecp
->fec_hash_table_high
= 0;
1840 fecp
->fec_hash_table_low
= 0;
1842 /* Set maximum receive buffer size.
1844 fecp
->fec_r_buff_size
= PKT_MAXBLR_SIZE
;
1845 fecp
->fec_r_hash
= PKT_MAXBUF_SIZE
;
1847 /* Set receive and transmit descriptor base.
1849 fecp
->fec_r_des_start
= iopa((uint
)(fep
->rx_bd_base
));
1850 fecp
->fec_x_des_start
= iopa((uint
)(fep
->tx_bd_base
));
1852 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
1853 fep
->cur_rx
= fep
->rx_bd_base
;
1855 /* Reset SKB transmit buffers.
1857 fep
->skb_cur
= fep
->skb_dirty
= 0;
1858 for (i
=0; i
<=TX_RING_MOD_MASK
; i
++) {
1859 if (fep
->tx_skbuff
[i
] != NULL
) {
1860 dev_kfree_skb(fep
->tx_skbuff
[i
]);
1861 fep
->tx_skbuff
[i
] = NULL
;
1865 /* Initialize the receive buffer descriptors.
1867 bdp
= fep
->rx_bd_base
;
1868 for (i
=0; i
<RX_RING_SIZE
; i
++) {
1870 /* Initialize the BD for every fragment in the page.
1872 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
1876 /* Set the last buffer to wrap.
1879 bdp
->cbd_sc
|= BD_SC_WRAP
;
1881 /* ...and the same for transmit.
1883 bdp
= fep
->tx_bd_base
;
1884 for (i
=0; i
<TX_RING_SIZE
; i
++) {
1886 /* Initialize the BD for every fragment in the page.
1889 bdp
->cbd_bufaddr
= 0;
1893 /* Set the last buffer to wrap.
1896 bdp
->cbd_sc
|= BD_SC_WRAP
;
1901 fecp
->fec_r_cntrl
= FEC_RCNTRL_MII_MODE
; /* MII enable */
1902 fecp
->fec_x_cntrl
= FEC_TCNTRL_FDEN
; /* FD enable */
1905 fecp
->fec_r_cntrl
= FEC_RCNTRL_MII_MODE
| FEC_RCNTRL_DRT
;
1906 fecp
->fec_x_cntrl
= 0;
1908 fep
->full_duplex
= duplex
;
1910 /* Enable big endian and don't care about SDMA FC.
1912 fecp
->fec_fun_code
= 0x78000000;
1914 #ifdef CONFIG_USE_MDIO
1917 fecp
->fec_mii_speed
= fep
->phy_speed
;
1918 #endif /* CONFIG_USE_MDIO */
1920 /* Clear any outstanding interrupt.
1922 fecp
->fec_ievent
= 0xffc0;
1924 fecp
->fec_ivec
= (FEC_INTERRUPT
/2) << 29;
1926 /* Enable interrupts we wish to service.
1928 fecp
->fec_imask
= ( FEC_ENET_TXF
| FEC_ENET_TXB
|
1929 FEC_ENET_RXF
| FEC_ENET_RXB
| FEC_ENET_MII
);
1931 /* And last, enable the transmit and receive processing.
1933 fecp
->fec_ecntrl
= FEC_ECNTRL_PINMUX
| FEC_ECNTRL_ETHER_EN
;
1934 fecp
->fec_r_des_active
= 0x01000000;
1938 fec_stop(struct net_device
*dev
)
1940 volatile immap_t
*immap
;
1941 volatile fec_t
*fecp
;
1942 struct fec_enet_private
*fep
;
1945 immap
= (immap_t
*)IMAP_ADDR
; /* pointer to internal registers */
1947 fecp
= &(immap
->im_cpm
.cp_fec
);
1949 if ((fecp
->fec_ecntrl
& FEC_ECNTRL_ETHER_EN
) == 0)
1950 return; /* already down */
1955 fecp
->fec_x_cntrl
= 0x01; /* Graceful transmit stop */
1958 ((fecp
->fec_ievent
& 0x10000000) == 0) && (i
< FEC_RESET_DELAY
);
1962 if (i
== FEC_RESET_DELAY
) {
1963 printk ("FEC timeout on graceful transmit stop\n");
1966 /* Clear outstanding MII command interrupts.
1968 fecp
->fec_ievent
= FEC_ENET_MII
;
1970 /* Enable MII command finished interrupt
1972 fecp
->fec_ivec
= (FEC_INTERRUPT
/2) << 29;
1973 fecp
->fec_imask
= FEC_ENET_MII
;
1975 #ifdef CONFIG_USE_MDIO
1978 fecp
->fec_mii_speed
= fep
->phy_speed
;
1979 #endif /* CONFIG_USE_MDIO */
1983 fecp
->fec_ecntrl
&= ~(FEC_ECNTRL_ETHER_EN
);