2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
5 * Right now, I am very wasteful with the buffers. I allocate memory
6 * pages and then divide them into 2K frame buffers. This way I know I
7 * have buffers large enough to hold one frame within one buffer descriptor.
8 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
9 * will be much more memory efficient and will easily handle lots of
12 * Much better multiple PHY support by Magnus Damm.
13 * Copyright (c) 2000 Ericsson Radio Systems AB.
15 * Support for FEC controller of ColdFire processors.
16 * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
18 * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
19 * Copyright (c) 2004-2006 Macq Electronique SA.
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/ptrace.h>
26 #include <linux/errno.h>
27 #include <linux/ioport.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/pci.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/skbuff.h>
36 #include <linux/spinlock.h>
37 #include <linux/workqueue.h>
38 #include <linux/bitops.h>
41 #include <asm/uaccess.h>
43 #include <asm/pgtable.h>
44 #include <asm/cacheflush.h>
46 #include <asm/coldfire.h>
47 #include <asm/mcfsim.h>
50 #if defined(CONFIG_FEC2)
51 #define FEC_MAX_PORTS 2
53 #define FEC_MAX_PORTS 1
56 #if defined(CONFIG_M5272)
57 #define HAVE_mii_link_interrupt
61 * Define the fixed address of the FEC hardware.
63 static unsigned int fec_hw
[] = {
64 #if defined(CONFIG_M5272)
66 #elif defined(CONFIG_M527x)
69 #elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
71 #elif defined(CONFIG_M520x)
73 #elif defined(CONFIG_M532x)
74 (MCF_MBAR
+0xfc030000),
78 static unsigned char fec_mac_default
[] = {
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 * Some hardware gets it MAC address out of local flash memory.
84 * if this is non-zero then assume it is the address to get MAC from.
86 #if defined(CONFIG_NETtel)
87 #define FEC_FLASHMAC 0xf0006006
88 #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
89 #define FEC_FLASHMAC 0xf0006000
90 #elif defined(CONFIG_CANCam)
91 #define FEC_FLASHMAC 0xf0020000
92 #elif defined (CONFIG_M5272C3)
93 #define FEC_FLASHMAC (0xffe04000 + 4)
94 #elif defined(CONFIG_MOD5272)
95 #define FEC_FLASHMAC 0xffc0406b
97 #define FEC_FLASHMAC 0
100 /* Forward declarations of some structures to support different PHYs
105 void (*funct
)(uint mii_reg
, struct net_device
*dev
);
112 const phy_cmd_t
*config
;
113 const phy_cmd_t
*startup
;
114 const phy_cmd_t
*ack_int
;
115 const phy_cmd_t
*shutdown
;
118 /* The number of Tx and Rx buffers. These are allocated from the page
119 * pool. The code may assume these are power of two, so it it best
120 * to keep them that size.
121 * We don't need to allocate pages for the transmitter. We just use
122 * the skbuffer directly.
124 #define FEC_ENET_RX_PAGES 8
125 #define FEC_ENET_RX_FRSIZE 2048
126 #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
127 #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
128 #define FEC_ENET_TX_FRSIZE 2048
129 #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)
130 #define TX_RING_SIZE 16 /* Must be power of two */
131 #define TX_RING_MOD_MASK 15 /* for this to work */
133 #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
134 #error "FEC: descriptor ring size constants too large"
137 /* Interrupt events/masks.
139 #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
140 #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
141 #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
142 #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
143 #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
144 #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
145 #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
146 #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
147 #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
148 #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
150 /* The FEC stores dest/src/type, data, and checksum for receive packets.
152 #define PKT_MAXBUF_SIZE 1518
153 #define PKT_MINBUF_SIZE 64
154 #define PKT_MAXBLR_SIZE 1520
158 * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
159 * size bits. Other FEC hardware does not, so we need to take that into
160 * account when setting it.
162 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
163 defined(CONFIG_M520x) || defined(CONFIG_M532x)
164 #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16)
166 #define OPT_FRAME_SIZE 0
169 /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and
170 * tx_bd_base always point to the base of the buffer descriptors. The
171 * cur_rx and cur_tx point to the currently available buffer.
172 * The dirty_tx tracks the current buffer that is being sent by the
173 * controller. The cur_tx and dirty_tx are equal under both completely
174 * empty and completely full conditions. The empty/ready indicator in
175 * the buffer descriptor determines the actual condition.
177 struct fec_enet_private
{
178 /* Hardware registers of the FEC device */
181 struct net_device
*netdev
;
183 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
184 unsigned char *tx_bounce
[TX_RING_SIZE
];
185 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
189 /* CPM dual port RAM relative addresses.
191 cbd_t
*rx_bd_base
; /* Address of Rx and Tx buffers. */
193 cbd_t
*cur_rx
, *cur_tx
; /* The next free ring entry */
194 cbd_t
*dirty_tx
; /* The ring entries to be free()ed. */
196 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
198 /* hold while accessing the mii_list_t() elements */
205 phy_info_t
const *phy
;
206 struct work_struct phy_task
;
209 uint mii_phy_task_queued
;
220 static int fec_enet_open(struct net_device
*dev
);
221 static int fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
222 static void fec_enet_mii(struct net_device
*dev
);
223 static irqreturn_t
fec_enet_interrupt(int irq
, void * dev_id
);
224 static void fec_enet_tx(struct net_device
*dev
);
225 static void fec_enet_rx(struct net_device
*dev
);
226 static int fec_enet_close(struct net_device
*dev
);
227 static void set_multicast_list(struct net_device
*dev
);
228 static void fec_restart(struct net_device
*dev
, int duplex
);
229 static void fec_stop(struct net_device
*dev
);
230 static void fec_set_mac_address(struct net_device
*dev
);
233 /* MII processing. We keep this as simple as possible. Requests are
234 * placed on the list (if there is room). When the request is finished
235 * by the MII, an optional function may be called.
237 typedef struct mii_list
{
239 void (*mii_func
)(uint val
, struct net_device
*dev
);
240 struct mii_list
*mii_next
;
244 static mii_list_t mii_cmds
[NMII
];
245 static mii_list_t
*mii_free
;
246 static mii_list_t
*mii_head
;
247 static mii_list_t
*mii_tail
;
249 static int mii_queue(struct net_device
*dev
, int request
,
250 void (*func
)(uint
, struct net_device
*));
252 /* Make MII read/write commands for the FEC.
254 #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
255 #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \
259 /* Transmitter timeout.
261 #define TX_TIMEOUT (2*HZ)
263 /* Register definitions for the PHY.
266 #define MII_REG_CR 0 /* Control Register */
267 #define MII_REG_SR 1 /* Status Register */
268 #define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */
269 #define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */
270 #define MII_REG_ANAR 4 /* A-N Advertisement Register */
271 #define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */
272 #define MII_REG_ANER 6 /* A-N Expansion Register */
273 #define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */
274 #define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */
276 /* values for phy_status */
278 #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */
279 #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */
280 #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */
281 #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */
282 #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */
283 #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */
284 #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */
286 #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */
287 #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */
288 #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */
289 #define PHY_STAT_SPMASK 0xf000 /* mask for speed */
290 #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */
291 #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */
292 #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */
293 #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */
297 fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
299 struct fec_enet_private
*fep
;
300 volatile fec_t
*fecp
;
302 unsigned short status
;
305 fep
= netdev_priv(dev
);
306 fecp
= (volatile fec_t
*)dev
->base_addr
;
309 /* Link is down or autonegotiation is in progress. */
313 spin_lock_irqsave(&fep
->hw_lock
, flags
);
314 /* Fill in a Tx ring entry */
317 status
= bdp
->cbd_sc
;
318 #ifndef final_version
319 if (status
& BD_ENET_TX_READY
) {
320 /* Ooops. All transmit buffers are full. Bail out.
321 * This should not happen, since dev->tbusy should be set.
323 printk("%s: tx queue full!.\n", dev
->name
);
324 spin_unlock_irqrestore(&fep
->hw_lock
, flags
);
329 /* Clear all of the status flags.
331 status
&= ~BD_ENET_TX_STATS
;
333 /* Set buffer length and buffer pointer.
335 bdp
->cbd_bufaddr
= __pa(skb
->data
);
336 bdp
->cbd_datlen
= skb
->len
;
339 * On some FEC implementations data must be aligned on
340 * 4-byte boundaries. Use bounce buffers to copy data
341 * and get it aligned. Ugh.
343 if (bdp
->cbd_bufaddr
& 0x3) {
345 index
= bdp
- fep
->tx_bd_base
;
346 memcpy(fep
->tx_bounce
[index
], (void *) bdp
->cbd_bufaddr
, bdp
->cbd_datlen
);
347 bdp
->cbd_bufaddr
= __pa(fep
->tx_bounce
[index
]);
352 fep
->tx_skbuff
[fep
->skb_cur
] = skb
;
354 dev
->stats
.tx_bytes
+= skb
->len
;
355 fep
->skb_cur
= (fep
->skb_cur
+1) & TX_RING_MOD_MASK
;
357 /* Push the data cache so the CPM does not get stale memory
360 flush_dcache_range((unsigned long)skb
->data
,
361 (unsigned long)skb
->data
+ skb
->len
);
363 /* Send it on its way. Tell FEC it's ready, interrupt when done,
364 * it's the last BD of the frame, and to put the CRC on the end.
367 status
|= (BD_ENET_TX_READY
| BD_ENET_TX_INTR
368 | BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
369 bdp
->cbd_sc
= status
;
371 dev
->trans_start
= jiffies
;
373 /* Trigger transmission start */
374 fecp
->fec_x_des_active
= 0;
376 /* If this was the last BD in the ring, start at the beginning again.
378 if (status
& BD_ENET_TX_WRAP
) {
379 bdp
= fep
->tx_bd_base
;
384 if (bdp
== fep
->dirty_tx
) {
386 netif_stop_queue(dev
);
389 fep
->cur_tx
= (cbd_t
*)bdp
;
391 spin_unlock_irqrestore(&fep
->hw_lock
, flags
);
397 fec_timeout(struct net_device
*dev
)
399 struct fec_enet_private
*fep
= netdev_priv(dev
);
401 printk("%s: transmit timed out.\n", dev
->name
);
402 dev
->stats
.tx_errors
++;
403 #ifndef final_version
408 printk("Ring data dump: cur_tx %lx%s, dirty_tx %lx cur_rx: %lx\n",
409 (unsigned long)fep
->cur_tx
, fep
->tx_full
? " (full)" : "",
410 (unsigned long)fep
->dirty_tx
,
411 (unsigned long)fep
->cur_rx
);
413 bdp
= fep
->tx_bd_base
;
414 printk(" tx: %u buffers\n", TX_RING_SIZE
);
415 for (i
= 0 ; i
< TX_RING_SIZE
; i
++) {
416 printk(" %08x: %04x %04x %08x\n",
420 (int) bdp
->cbd_bufaddr
);
424 bdp
= fep
->rx_bd_base
;
425 printk(" rx: %lu buffers\n", (unsigned long) RX_RING_SIZE
);
426 for (i
= 0 ; i
< RX_RING_SIZE
; i
++) {
427 printk(" %08x: %04x %04x %08x\n",
431 (int) bdp
->cbd_bufaddr
);
436 fec_restart(dev
, fep
->full_duplex
);
437 netif_wake_queue(dev
);
440 /* The interrupt handler.
441 * This is called from the MPC core interrupt.
444 fec_enet_interrupt(int irq
, void * dev_id
)
446 struct net_device
*dev
= dev_id
;
447 volatile fec_t
*fecp
;
449 irqreturn_t ret
= IRQ_NONE
;
451 fecp
= (volatile fec_t
*)dev
->base_addr
;
453 /* Get the interrupt events that caused us to be here.
456 int_events
= fecp
->fec_ievent
;
457 fecp
->fec_ievent
= int_events
;
459 /* Handle receive event in its own function.
461 if (int_events
& FEC_ENET_RXF
) {
466 /* Transmit OK, or non-fatal error. Update the buffer
467 descriptors. FEC handles all errors, we just discover
468 them as part of the transmit process.
470 if (int_events
& FEC_ENET_TXF
) {
475 if (int_events
& FEC_ENET_MII
) {
480 } while (int_events
);
487 fec_enet_tx(struct net_device
*dev
)
489 struct fec_enet_private
*fep
;
491 unsigned short status
;
494 fep
= netdev_priv(dev
);
495 spin_lock_irq(&fep
->hw_lock
);
498 while (((status
= bdp
->cbd_sc
) & BD_ENET_TX_READY
) == 0) {
499 if (bdp
== fep
->cur_tx
&& fep
->tx_full
== 0) break;
501 skb
= fep
->tx_skbuff
[fep
->skb_dirty
];
502 /* Check for errors. */
503 if (status
& (BD_ENET_TX_HB
| BD_ENET_TX_LC
|
504 BD_ENET_TX_RL
| BD_ENET_TX_UN
|
506 dev
->stats
.tx_errors
++;
507 if (status
& BD_ENET_TX_HB
) /* No heartbeat */
508 dev
->stats
.tx_heartbeat_errors
++;
509 if (status
& BD_ENET_TX_LC
) /* Late collision */
510 dev
->stats
.tx_window_errors
++;
511 if (status
& BD_ENET_TX_RL
) /* Retrans limit */
512 dev
->stats
.tx_aborted_errors
++;
513 if (status
& BD_ENET_TX_UN
) /* Underrun */
514 dev
->stats
.tx_fifo_errors
++;
515 if (status
& BD_ENET_TX_CSL
) /* Carrier lost */
516 dev
->stats
.tx_carrier_errors
++;
518 dev
->stats
.tx_packets
++;
521 #ifndef final_version
522 if (status
& BD_ENET_TX_READY
)
523 printk("HEY! Enet xmit interrupt and TX_READY.\n");
525 /* Deferred means some collisions occurred during transmit,
526 * but we eventually sent the packet OK.
528 if (status
& BD_ENET_TX_DEF
)
529 dev
->stats
.collisions
++;
531 /* Free the sk buffer associated with this last transmit.
533 dev_kfree_skb_any(skb
);
534 fep
->tx_skbuff
[fep
->skb_dirty
] = NULL
;
535 fep
->skb_dirty
= (fep
->skb_dirty
+ 1) & TX_RING_MOD_MASK
;
537 /* Update pointer to next buffer descriptor to be transmitted.
539 if (status
& BD_ENET_TX_WRAP
)
540 bdp
= fep
->tx_bd_base
;
544 /* Since we have freed up a buffer, the ring is no longer
549 if (netif_queue_stopped(dev
))
550 netif_wake_queue(dev
);
553 fep
->dirty_tx
= (cbd_t
*)bdp
;
554 spin_unlock_irq(&fep
->hw_lock
);
558 /* During a receive, the cur_rx points to the current incoming buffer.
559 * When we update through the ring, if the next incoming buffer has
560 * not been given to the system, we just set the empty indicator,
561 * effectively tossing the packet.
564 fec_enet_rx(struct net_device
*dev
)
566 struct fec_enet_private
*fep
;
567 volatile fec_t
*fecp
;
569 unsigned short status
;
578 fep
= netdev_priv(dev
);
579 fecp
= (volatile fec_t
*)dev
->base_addr
;
581 spin_lock_irq(&fep
->hw_lock
);
583 /* First, grab all of the stats for the incoming packet.
584 * These get messed up if we get called due to a busy condition.
588 while (!((status
= bdp
->cbd_sc
) & BD_ENET_RX_EMPTY
)) {
590 #ifndef final_version
591 /* Since we have allocated space to hold a complete frame,
592 * the last indicator should be set.
594 if ((status
& BD_ENET_RX_LAST
) == 0)
595 printk("FEC ENET: rcv is not +last\n");
599 goto rx_processing_done
;
601 /* Check for errors. */
602 if (status
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
| BD_ENET_RX_NO
|
603 BD_ENET_RX_CR
| BD_ENET_RX_OV
)) {
604 dev
->stats
.rx_errors
++;
605 if (status
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
)) {
606 /* Frame too long or too short. */
607 dev
->stats
.rx_length_errors
++;
609 if (status
& BD_ENET_RX_NO
) /* Frame alignment */
610 dev
->stats
.rx_frame_errors
++;
611 if (status
& BD_ENET_RX_CR
) /* CRC Error */
612 dev
->stats
.rx_crc_errors
++;
613 if (status
& BD_ENET_RX_OV
) /* FIFO overrun */
614 dev
->stats
.rx_fifo_errors
++;
617 /* Report late collisions as a frame error.
618 * On this error, the BD is closed, but we don't know what we
619 * have in the buffer. So, just drop this frame on the floor.
621 if (status
& BD_ENET_RX_CL
) {
622 dev
->stats
.rx_errors
++;
623 dev
->stats
.rx_frame_errors
++;
624 goto rx_processing_done
;
627 /* Process the incoming frame.
629 dev
->stats
.rx_packets
++;
630 pkt_len
= bdp
->cbd_datlen
;
631 dev
->stats
.rx_bytes
+= pkt_len
;
632 data
= (__u8
*)__va(bdp
->cbd_bufaddr
);
634 /* This does 16 byte alignment, exactly what we need.
635 * The packet length includes FCS, but we don't want to
636 * include that when passing upstream as it messes up
637 * bridging applications.
639 skb
= dev_alloc_skb(pkt_len
-4);
642 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
643 dev
->stats
.rx_dropped
++;
645 skb_put(skb
,pkt_len
-4); /* Make room */
646 skb_copy_to_linear_data(skb
, data
, pkt_len
-4);
647 skb
->protocol
=eth_type_trans(skb
,dev
);
652 /* Clear the status flags for this buffer.
654 status
&= ~BD_ENET_RX_STATS
;
656 /* Mark the buffer empty.
658 status
|= BD_ENET_RX_EMPTY
;
659 bdp
->cbd_sc
= status
;
661 /* Update BD pointer to next entry.
663 if (status
& BD_ENET_RX_WRAP
)
664 bdp
= fep
->rx_bd_base
;
669 /* Doing this here will keep the FEC running while we process
670 * incoming frames. On a heavily loaded network, we should be
671 * able to keep up at the expense of system resources.
673 fecp
->fec_r_des_active
= 0;
675 } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
676 fep
->cur_rx
= (cbd_t
*)bdp
;
679 /* Doing this here will allow us to process all frames in the
680 * ring before the FEC is allowed to put more there. On a heavily
681 * loaded network, some frames may be lost. Unfortunately, this
682 * increases the interrupt overhead since we can potentially work
683 * our way back to the interrupt return only to come right back
686 fecp
->fec_r_des_active
= 0;
689 spin_unlock_irq(&fep
->hw_lock
);
693 /* called from interrupt context */
695 fec_enet_mii(struct net_device
*dev
)
697 struct fec_enet_private
*fep
;
702 fep
= netdev_priv(dev
);
703 spin_lock_irq(&fep
->mii_lock
);
706 mii_reg
= ep
->fec_mii_data
;
708 if ((mip
= mii_head
) == NULL
) {
709 printk("MII and no head!\n");
713 if (mip
->mii_func
!= NULL
)
714 (*(mip
->mii_func
))(mii_reg
, dev
);
716 mii_head
= mip
->mii_next
;
717 mip
->mii_next
= mii_free
;
720 if ((mip
= mii_head
) != NULL
)
721 ep
->fec_mii_data
= mip
->mii_regval
;
724 spin_unlock_irq(&fep
->mii_lock
);
728 mii_queue(struct net_device
*dev
, int regval
, void (*func
)(uint
, struct net_device
*))
730 struct fec_enet_private
*fep
;
735 /* Add PHY address to register command.
737 fep
= netdev_priv(dev
);
738 spin_lock_irqsave(&fep
->mii_lock
, flags
);
740 regval
|= fep
->phy_addr
<< 23;
743 if ((mip
= mii_free
) != NULL
) {
744 mii_free
= mip
->mii_next
;
745 mip
->mii_regval
= regval
;
746 mip
->mii_func
= func
;
747 mip
->mii_next
= NULL
;
749 mii_tail
->mii_next
= mip
;
752 mii_head
= mii_tail
= mip
;
753 fep
->hwp
->fec_mii_data
= regval
;
759 spin_unlock_irqrestore(&fep
->mii_lock
, flags
);
763 static void mii_do_cmd(struct net_device
*dev
, const phy_cmd_t
*c
)
768 for (; c
->mii_data
!= mk_mii_end
; c
++)
769 mii_queue(dev
, c
->mii_data
, c
->funct
);
772 static void mii_parse_sr(uint mii_reg
, struct net_device
*dev
)
774 struct fec_enet_private
*fep
= netdev_priv(dev
);
775 volatile uint
*s
= &(fep
->phy_status
);
778 status
= *s
& ~(PHY_STAT_LINK
| PHY_STAT_FAULT
| PHY_STAT_ANC
);
780 if (mii_reg
& 0x0004)
781 status
|= PHY_STAT_LINK
;
782 if (mii_reg
& 0x0010)
783 status
|= PHY_STAT_FAULT
;
784 if (mii_reg
& 0x0020)
785 status
|= PHY_STAT_ANC
;
789 static void mii_parse_cr(uint mii_reg
, struct net_device
*dev
)
791 struct fec_enet_private
*fep
= netdev_priv(dev
);
792 volatile uint
*s
= &(fep
->phy_status
);
795 status
= *s
& ~(PHY_CONF_ANE
| PHY_CONF_LOOP
);
797 if (mii_reg
& 0x1000)
798 status
|= PHY_CONF_ANE
;
799 if (mii_reg
& 0x4000)
800 status
|= PHY_CONF_LOOP
;
804 static void mii_parse_anar(uint mii_reg
, struct net_device
*dev
)
806 struct fec_enet_private
*fep
= netdev_priv(dev
);
807 volatile uint
*s
= &(fep
->phy_status
);
810 status
= *s
& ~(PHY_CONF_SPMASK
);
812 if (mii_reg
& 0x0020)
813 status
|= PHY_CONF_10HDX
;
814 if (mii_reg
& 0x0040)
815 status
|= PHY_CONF_10FDX
;
816 if (mii_reg
& 0x0080)
817 status
|= PHY_CONF_100HDX
;
818 if (mii_reg
& 0x00100)
819 status
|= PHY_CONF_100FDX
;
823 /* ------------------------------------------------------------------------- */
824 /* The Level one LXT970 is used by many boards */
826 #define MII_LXT970_MIRROR 16 /* Mirror register */
827 #define MII_LXT970_IER 17 /* Interrupt Enable Register */
828 #define MII_LXT970_ISR 18 /* Interrupt Status Register */
829 #define MII_LXT970_CONFIG 19 /* Configuration Register */
830 #define MII_LXT970_CSR 20 /* Chip Status Register */
832 static void mii_parse_lxt970_csr(uint mii_reg
, struct net_device
*dev
)
834 struct fec_enet_private
*fep
= netdev_priv(dev
);
835 volatile uint
*s
= &(fep
->phy_status
);
838 status
= *s
& ~(PHY_STAT_SPMASK
);
839 if (mii_reg
& 0x0800) {
840 if (mii_reg
& 0x1000)
841 status
|= PHY_STAT_100FDX
;
843 status
|= PHY_STAT_100HDX
;
845 if (mii_reg
& 0x1000)
846 status
|= PHY_STAT_10FDX
;
848 status
|= PHY_STAT_10HDX
;
853 static phy_cmd_t
const phy_cmd_lxt970_config
[] = {
854 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
855 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
858 static phy_cmd_t
const phy_cmd_lxt970_startup
[] = { /* enable interrupts */
859 { mk_mii_write(MII_LXT970_IER
, 0x0002), NULL
},
860 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
863 static phy_cmd_t
const phy_cmd_lxt970_ack_int
[] = {
864 /* read SR and ISR to acknowledge */
865 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
866 { mk_mii_read(MII_LXT970_ISR
), NULL
},
868 /* find out the current status */
869 { mk_mii_read(MII_LXT970_CSR
), mii_parse_lxt970_csr
},
872 static phy_cmd_t
const phy_cmd_lxt970_shutdown
[] = { /* disable interrupts */
873 { mk_mii_write(MII_LXT970_IER
, 0x0000), NULL
},
876 static phy_info_t
const phy_info_lxt970
= {
879 .config
= phy_cmd_lxt970_config
,
880 .startup
= phy_cmd_lxt970_startup
,
881 .ack_int
= phy_cmd_lxt970_ack_int
,
882 .shutdown
= phy_cmd_lxt970_shutdown
885 /* ------------------------------------------------------------------------- */
886 /* The Level one LXT971 is used on some of my custom boards */
888 /* register definitions for the 971 */
890 #define MII_LXT971_PCR 16 /* Port Control Register */
891 #define MII_LXT971_SR2 17 /* Status Register 2 */
892 #define MII_LXT971_IER 18 /* Interrupt Enable Register */
893 #define MII_LXT971_ISR 19 /* Interrupt Status Register */
894 #define MII_LXT971_LCR 20 /* LED Control Register */
895 #define MII_LXT971_TCR 30 /* Transmit Control Register */
898 * I had some nice ideas of running the MDIO faster...
899 * The 971 should support 8MHz and I tried it, but things acted really
900 * weird, so 2.5 MHz ought to be enough for anyone...
903 static void mii_parse_lxt971_sr2(uint mii_reg
, struct net_device
*dev
)
905 struct fec_enet_private
*fep
= netdev_priv(dev
);
906 volatile uint
*s
= &(fep
->phy_status
);
909 status
= *s
& ~(PHY_STAT_SPMASK
| PHY_STAT_LINK
| PHY_STAT_ANC
);
911 if (mii_reg
& 0x0400) {
913 status
|= PHY_STAT_LINK
;
917 if (mii_reg
& 0x0080)
918 status
|= PHY_STAT_ANC
;
919 if (mii_reg
& 0x4000) {
920 if (mii_reg
& 0x0200)
921 status
|= PHY_STAT_100FDX
;
923 status
|= PHY_STAT_100HDX
;
925 if (mii_reg
& 0x0200)
926 status
|= PHY_STAT_10FDX
;
928 status
|= PHY_STAT_10HDX
;
930 if (mii_reg
& 0x0008)
931 status
|= PHY_STAT_FAULT
;
936 static phy_cmd_t
const phy_cmd_lxt971_config
[] = {
937 /* limit to 10MBit because my prototype board
938 * doesn't work with 100. */
939 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
940 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
941 { mk_mii_read(MII_LXT971_SR2
), mii_parse_lxt971_sr2
},
944 static phy_cmd_t
const phy_cmd_lxt971_startup
[] = { /* enable interrupts */
945 { mk_mii_write(MII_LXT971_IER
, 0x00f2), NULL
},
946 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
947 { mk_mii_write(MII_LXT971_LCR
, 0xd422), NULL
}, /* LED config */
948 /* Somehow does the 971 tell me that the link is down
949 * the first read after power-up.
950 * read here to get a valid value in ack_int */
951 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
954 static phy_cmd_t
const phy_cmd_lxt971_ack_int
[] = {
955 /* acknowledge the int before reading status ! */
956 { mk_mii_read(MII_LXT971_ISR
), NULL
},
957 /* find out the current status */
958 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
959 { mk_mii_read(MII_LXT971_SR2
), mii_parse_lxt971_sr2
},
962 static phy_cmd_t
const phy_cmd_lxt971_shutdown
[] = { /* disable interrupts */
963 { mk_mii_write(MII_LXT971_IER
, 0x0000), NULL
},
966 static phy_info_t
const phy_info_lxt971
= {
969 .config
= phy_cmd_lxt971_config
,
970 .startup
= phy_cmd_lxt971_startup
,
971 .ack_int
= phy_cmd_lxt971_ack_int
,
972 .shutdown
= phy_cmd_lxt971_shutdown
975 /* ------------------------------------------------------------------------- */
976 /* The Quality Semiconductor QS6612 is used on the RPX CLLF */
978 /* register definitions */
980 #define MII_QS6612_MCR 17 /* Mode Control Register */
981 #define MII_QS6612_FTR 27 /* Factory Test Register */
982 #define MII_QS6612_MCO 28 /* Misc. Control Register */
983 #define MII_QS6612_ISR 29 /* Interrupt Source Register */
984 #define MII_QS6612_IMR 30 /* Interrupt Mask Register */
985 #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */
987 static void mii_parse_qs6612_pcr(uint mii_reg
, struct net_device
*dev
)
989 struct fec_enet_private
*fep
= netdev_priv(dev
);
990 volatile uint
*s
= &(fep
->phy_status
);
993 status
= *s
& ~(PHY_STAT_SPMASK
);
995 switch((mii_reg
>> 2) & 7) {
996 case 1: status
|= PHY_STAT_10HDX
; break;
997 case 2: status
|= PHY_STAT_100HDX
; break;
998 case 5: status
|= PHY_STAT_10FDX
; break;
999 case 6: status
|= PHY_STAT_100FDX
; break;
1005 static phy_cmd_t
const phy_cmd_qs6612_config
[] = {
1006 /* The PHY powers up isolated on the RPX,
1007 * so send a command to allow operation.
1009 { mk_mii_write(MII_QS6612_PCR
, 0x0dc0), NULL
},
1011 /* parse cr and anar to get some info */
1012 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1013 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1016 static phy_cmd_t
const phy_cmd_qs6612_startup
[] = { /* enable interrupts */
1017 { mk_mii_write(MII_QS6612_IMR
, 0x003a), NULL
},
1018 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1021 static phy_cmd_t
const phy_cmd_qs6612_ack_int
[] = {
1022 /* we need to read ISR, SR and ANER to acknowledge */
1023 { mk_mii_read(MII_QS6612_ISR
), NULL
},
1024 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1025 { mk_mii_read(MII_REG_ANER
), NULL
},
1027 /* read pcr to get info */
1028 { mk_mii_read(MII_QS6612_PCR
), mii_parse_qs6612_pcr
},
1031 static phy_cmd_t
const phy_cmd_qs6612_shutdown
[] = { /* disable interrupts */
1032 { mk_mii_write(MII_QS6612_IMR
, 0x0000), NULL
},
1035 static phy_info_t
const phy_info_qs6612
= {
1038 .config
= phy_cmd_qs6612_config
,
1039 .startup
= phy_cmd_qs6612_startup
,
1040 .ack_int
= phy_cmd_qs6612_ack_int
,
1041 .shutdown
= phy_cmd_qs6612_shutdown
1044 /* ------------------------------------------------------------------------- */
1045 /* AMD AM79C874 phy */
1047 /* register definitions for the 874 */
1049 #define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */
1050 #define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */
1051 #define MII_AM79C874_DR 18 /* Diagnostic Register */
1052 #define MII_AM79C874_PMLR 19 /* Power and Loopback Register */
1053 #define MII_AM79C874_MCR 21 /* ModeControl Register */
1054 #define MII_AM79C874_DC 23 /* Disconnect Counter */
1055 #define MII_AM79C874_REC 24 /* Recieve Error Counter */
1057 static void mii_parse_am79c874_dr(uint mii_reg
, struct net_device
*dev
)
1059 struct fec_enet_private
*fep
= netdev_priv(dev
);
1060 volatile uint
*s
= &(fep
->phy_status
);
1063 status
= *s
& ~(PHY_STAT_SPMASK
| PHY_STAT_ANC
);
1065 if (mii_reg
& 0x0080)
1066 status
|= PHY_STAT_ANC
;
1067 if (mii_reg
& 0x0400)
1068 status
|= ((mii_reg
& 0x0800) ? PHY_STAT_100FDX
: PHY_STAT_100HDX
);
1070 status
|= ((mii_reg
& 0x0800) ? PHY_STAT_10FDX
: PHY_STAT_10HDX
);
1075 static phy_cmd_t
const phy_cmd_am79c874_config
[] = {
1076 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1077 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1078 { mk_mii_read(MII_AM79C874_DR
), mii_parse_am79c874_dr
},
1081 static phy_cmd_t
const phy_cmd_am79c874_startup
[] = { /* enable interrupts */
1082 { mk_mii_write(MII_AM79C874_ICSR
, 0xff00), NULL
},
1083 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1084 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1087 static phy_cmd_t
const phy_cmd_am79c874_ack_int
[] = {
1088 /* find out the current status */
1089 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1090 { mk_mii_read(MII_AM79C874_DR
), mii_parse_am79c874_dr
},
1091 /* we only need to read ISR to acknowledge */
1092 { mk_mii_read(MII_AM79C874_ICSR
), NULL
},
1095 static phy_cmd_t
const phy_cmd_am79c874_shutdown
[] = { /* disable interrupts */
1096 { mk_mii_write(MII_AM79C874_ICSR
, 0x0000), NULL
},
1099 static phy_info_t
const phy_info_am79c874
= {
1102 .config
= phy_cmd_am79c874_config
,
1103 .startup
= phy_cmd_am79c874_startup
,
1104 .ack_int
= phy_cmd_am79c874_ack_int
,
1105 .shutdown
= phy_cmd_am79c874_shutdown
1109 /* ------------------------------------------------------------------------- */
1110 /* Kendin KS8721BL phy */
1112 /* register definitions for the 8721 */
1114 #define MII_KS8721BL_RXERCR 21
1115 #define MII_KS8721BL_ICSR 22
1116 #define MII_KS8721BL_PHYCR 31
1118 static phy_cmd_t
const phy_cmd_ks8721bl_config
[] = {
1119 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1120 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1123 static phy_cmd_t
const phy_cmd_ks8721bl_startup
[] = { /* enable interrupts */
1124 { mk_mii_write(MII_KS8721BL_ICSR
, 0xff00), NULL
},
1125 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1126 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1129 static phy_cmd_t
const phy_cmd_ks8721bl_ack_int
[] = {
1130 /* find out the current status */
1131 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1132 /* we only need to read ISR to acknowledge */
1133 { mk_mii_read(MII_KS8721BL_ICSR
), NULL
},
1136 static phy_cmd_t
const phy_cmd_ks8721bl_shutdown
[] = { /* disable interrupts */
1137 { mk_mii_write(MII_KS8721BL_ICSR
, 0x0000), NULL
},
1140 static phy_info_t
const phy_info_ks8721bl
= {
1143 .config
= phy_cmd_ks8721bl_config
,
1144 .startup
= phy_cmd_ks8721bl_startup
,
1145 .ack_int
= phy_cmd_ks8721bl_ack_int
,
1146 .shutdown
= phy_cmd_ks8721bl_shutdown
1149 /* ------------------------------------------------------------------------- */
1150 /* register definitions for the DP83848 */
1152 #define MII_DP8384X_PHYSTST 16 /* PHY Status Register */
1154 static void mii_parse_dp8384x_sr2(uint mii_reg
, struct net_device
*dev
)
1156 struct fec_enet_private
*fep
= netdev_priv(dev
);
1157 volatile uint
*s
= &(fep
->phy_status
);
1159 *s
&= ~(PHY_STAT_SPMASK
| PHY_STAT_LINK
| PHY_STAT_ANC
);
1162 if (mii_reg
& 0x0001) {
1164 *s
|= PHY_STAT_LINK
;
1167 /* Status of link */
1168 if (mii_reg
& 0x0010) /* Autonegotioation complete */
1170 if (mii_reg
& 0x0002) { /* 10MBps? */
1171 if (mii_reg
& 0x0004) /* Full Duplex? */
1172 *s
|= PHY_STAT_10FDX
;
1174 *s
|= PHY_STAT_10HDX
;
1175 } else { /* 100 Mbps? */
1176 if (mii_reg
& 0x0004) /* Full Duplex? */
1177 *s
|= PHY_STAT_100FDX
;
1179 *s
|= PHY_STAT_100HDX
;
1181 if (mii_reg
& 0x0008)
1182 *s
|= PHY_STAT_FAULT
;
1185 static phy_info_t phy_info_dp83848
= {
1189 (const phy_cmd_t
[]) { /* config */
1190 { mk_mii_read(MII_REG_CR
), mii_parse_cr
},
1191 { mk_mii_read(MII_REG_ANAR
), mii_parse_anar
},
1192 { mk_mii_read(MII_DP8384X_PHYSTST
), mii_parse_dp8384x_sr2
},
1195 (const phy_cmd_t
[]) { /* startup - enable interrupts */
1196 { mk_mii_write(MII_REG_CR
, 0x1200), NULL
}, /* autonegotiate */
1197 { mk_mii_read(MII_REG_SR
), mii_parse_sr
},
1200 (const phy_cmd_t
[]) { /* ack_int - never happens, no interrupt */
1203 (const phy_cmd_t
[]) { /* shutdown */
1208 /* ------------------------------------------------------------------------- */
1210 static phy_info_t
const * const phy_info
[] = {
1220 /* ------------------------------------------------------------------------- */
1221 #ifdef HAVE_mii_link_interrupt
1223 mii_link_interrupt(int irq
, void * dev_id
);
1226 #if defined(CONFIG_M5272)
1228 * Code specific to Coldfire 5272 setup.
1230 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1232 volatile unsigned long *icrp
;
1233 static const struct idesc
{
1236 irq_handler_t handler
;
1238 { "fec(RX)", 86, fec_enet_interrupt
},
1239 { "fec(TX)", 87, fec_enet_interrupt
},
1240 { "fec(OTHER)", 88, fec_enet_interrupt
},
1241 { "fec(MII)", 66, mii_link_interrupt
},
1245 /* Setup interrupt handlers. */
1246 for (idp
= id
; idp
->name
; idp
++) {
1247 if (request_irq(idp
->irq
, idp
->handler
, IRQF_DISABLED
, idp
->name
, dev
) != 0)
1248 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp
->name
, idp
->irq
);
1251 /* Unmask interrupt at ColdFire 5272 SIM */
1252 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR3
);
1254 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1258 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1260 volatile fec_t
*fecp
;
1263 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1264 fecp
->fec_x_cntrl
= 0x00;
1267 * Set MII speed to 2.5 MHz
1268 * See 5272 manual section 11.5.8: MSCR
1270 fep
->phy_speed
= ((((MCF_CLK
/ 4) / (2500000 / 10)) + 5) / 10) * 2;
1271 fecp
->fec_mii_speed
= fep
->phy_speed
;
1273 fec_restart(dev
, 0);
1276 static void __inline__
fec_get_mac(struct net_device
*dev
)
1278 struct fec_enet_private
*fep
= netdev_priv(dev
);
1279 volatile fec_t
*fecp
;
1280 unsigned char *iap
, tmpaddr
[ETH_ALEN
];
1286 * Get MAC address from FLASH.
1287 * If it is all 1's or 0's, use the default.
1289 iap
= (unsigned char *)FEC_FLASHMAC
;
1290 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1291 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1292 iap
= fec_mac_default
;
1293 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1294 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1295 iap
= fec_mac_default
;
1297 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1298 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1302 memcpy(dev
->dev_addr
, iap
, ETH_ALEN
);
1304 /* Adjust MAC if using default MAC address */
1305 if (iap
== fec_mac_default
)
1306 dev
->dev_addr
[ETH_ALEN
-1] = fec_mac_default
[ETH_ALEN
-1] + fep
->index
;
1309 static void __inline__
fec_disable_phy_intr(void)
1311 volatile unsigned long *icrp
;
1312 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1316 static void __inline__
fec_phy_ack_intr(void)
1318 volatile unsigned long *icrp
;
1319 /* Acknowledge the interrupt */
1320 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR1
);
1324 /* ------------------------------------------------------------------------- */
1326 #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1329 * Code specific to Coldfire 5230/5231/5232/5234/5235,
1330 * the 5270/5271/5274/5275 and 5280/5282 setups.
1332 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1334 struct fec_enet_private
*fep
;
1336 static const struct idesc
{
1346 fep
= netdev_priv(dev
);
1347 b
= (fep
->index
) ? 128 : 64;
1349 /* Setup interrupt handlers. */
1350 for (idp
= id
; idp
->name
; idp
++) {
1351 if (request_irq(b
+idp
->irq
, fec_enet_interrupt
, IRQF_DISABLED
, idp
->name
, dev
) != 0)
1352 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp
->name
, b
+idp
->irq
);
1355 /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
1357 volatile unsigned char *icrp
;
1358 volatile unsigned long *imrp
;
1361 b
= (fep
->index
) ? MCFICM_INTC1
: MCFICM_INTC0
;
1362 icrp
= (volatile unsigned char *) (MCF_IPSBAR
+ b
+
1364 for (i
= 23, ilip
= 0x28; (i
< 36); i
++)
1367 imrp
= (volatile unsigned long *) (MCF_IPSBAR
+ b
+
1369 *imrp
&= ~0x0000000f;
1370 imrp
= (volatile unsigned long *) (MCF_IPSBAR
+ b
+
1372 *imrp
&= ~0xff800001;
1375 #if defined(CONFIG_M528x)
1376 /* Set up gpio outputs for MII lines */
1378 volatile u16
*gpio_paspar
;
1379 volatile u8
*gpio_pehlpar
;
1381 gpio_paspar
= (volatile u16
*) (MCF_IPSBAR
+ 0x100056);
1382 gpio_pehlpar
= (volatile u16
*) (MCF_IPSBAR
+ 0x100058);
1383 *gpio_paspar
|= 0x0f00;
1384 *gpio_pehlpar
= 0xc0;
1388 #if defined(CONFIG_M527x)
1389 /* Set up gpio outputs for MII lines */
1391 volatile u8
*gpio_par_fec
;
1392 volatile u16
*gpio_par_feci2c
;
1394 gpio_par_feci2c
= (volatile u16
*)(MCF_IPSBAR
+ 0x100082);
1395 /* Set up gpio outputs for FEC0 MII lines */
1396 gpio_par_fec
= (volatile u8
*)(MCF_IPSBAR
+ 0x100078);
1398 *gpio_par_feci2c
|= 0x0f00;
1399 *gpio_par_fec
|= 0xc0;
1401 #if defined(CONFIG_FEC2)
1402 /* Set up gpio outputs for FEC1 MII lines */
1403 gpio_par_fec
= (volatile u8
*)(MCF_IPSBAR
+ 0x100079);
1405 *gpio_par_feci2c
|= 0x00a0;
1406 *gpio_par_fec
|= 0xc0;
1407 #endif /* CONFIG_FEC2 */
1409 #endif /* CONFIG_M527x */
1412 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1414 volatile fec_t
*fecp
;
1417 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1418 fecp
->fec_x_cntrl
= 0x00;
1421 * Set MII speed to 2.5 MHz
1422 * See 5282 manual section 17.5.4.7: MSCR
1424 fep
->phy_speed
= ((((MCF_CLK
/ 2) / (2500000 / 10)) + 5) / 10) * 2;
1425 fecp
->fec_mii_speed
= fep
->phy_speed
;
1427 fec_restart(dev
, 0);
1430 static void __inline__
fec_get_mac(struct net_device
*dev
)
1432 struct fec_enet_private
*fep
= netdev_priv(dev
);
1433 volatile fec_t
*fecp
;
1434 unsigned char *iap
, tmpaddr
[ETH_ALEN
];
1440 * Get MAC address from FLASH.
1441 * If it is all 1's or 0's, use the default.
1444 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1445 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1446 iap
= fec_mac_default
;
1447 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1448 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1449 iap
= fec_mac_default
;
1451 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1452 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1456 memcpy(dev
->dev_addr
, iap
, ETH_ALEN
);
1458 /* Adjust MAC if using default MAC address */
1459 if (iap
== fec_mac_default
)
1460 dev
->dev_addr
[ETH_ALEN
-1] = fec_mac_default
[ETH_ALEN
-1] + fep
->index
;
1463 static void __inline__
fec_disable_phy_intr(void)
1467 static void __inline__
fec_phy_ack_intr(void)
1471 /* ------------------------------------------------------------------------- */
1473 #elif defined(CONFIG_M520x)
1476 * Code specific to Coldfire 520x
1478 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1480 struct fec_enet_private
*fep
;
1482 static const struct idesc
{
1492 fep
= netdev_priv(dev
);
1495 /* Setup interrupt handlers. */
1496 for (idp
= id
; idp
->name
; idp
++) {
1497 if (request_irq(b
+idp
->irq
, fec_enet_interrupt
, IRQF_DISABLED
, idp
->name
,dev
) != 0)
1498 printk("FEC: Could not allocate %s IRQ(%d)!\n", idp
->name
, b
+idp
->irq
);
1501 /* Unmask interrupts at ColdFire interrupt controller */
1503 volatile unsigned char *icrp
;
1504 volatile unsigned long *imrp
;
1506 icrp
= (volatile unsigned char *) (MCF_IPSBAR
+ MCFICM_INTC0
+
1508 for (b
= 36; (b
< 49); b
++)
1510 imrp
= (volatile unsigned long *) (MCF_IPSBAR
+ MCFICM_INTC0
+
1512 *imrp
&= ~0x0001FFF0;
1514 *(volatile unsigned char *)(MCF_IPSBAR
+ MCF_GPIO_PAR_FEC
) |= 0xf0;
1515 *(volatile unsigned char *)(MCF_IPSBAR
+ MCF_GPIO_PAR_FECI2C
) |= 0x0f;
1518 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1520 volatile fec_t
*fecp
;
1523 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1524 fecp
->fec_x_cntrl
= 0x00;
1527 * Set MII speed to 2.5 MHz
1528 * See 5282 manual section 17.5.4.7: MSCR
1530 fep
->phy_speed
= ((((MCF_CLK
/ 2) / (2500000 / 10)) + 5) / 10) * 2;
1531 fecp
->fec_mii_speed
= fep
->phy_speed
;
1533 fec_restart(dev
, 0);
1536 static void __inline__
fec_get_mac(struct net_device
*dev
)
1538 struct fec_enet_private
*fep
= netdev_priv(dev
);
1539 volatile fec_t
*fecp
;
1540 unsigned char *iap
, tmpaddr
[ETH_ALEN
];
1546 * Get MAC address from FLASH.
1547 * If it is all 1's or 0's, use the default.
1550 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1551 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1552 iap
= fec_mac_default
;
1553 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1554 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1555 iap
= fec_mac_default
;
1557 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1558 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1562 memcpy(dev
->dev_addr
, iap
, ETH_ALEN
);
1564 /* Adjust MAC if using default MAC address */
1565 if (iap
== fec_mac_default
)
1566 dev
->dev_addr
[ETH_ALEN
-1] = fec_mac_default
[ETH_ALEN
-1] + fep
->index
;
1569 static void __inline__
fec_disable_phy_intr(void)
1573 static void __inline__
fec_phy_ack_intr(void)
1577 /* ------------------------------------------------------------------------- */
1579 #elif defined(CONFIG_M532x)
1581 * Code specific for M532x
1583 static void __inline__
fec_request_intrs(struct net_device
*dev
)
1585 struct fec_enet_private
*fep
;
1587 static const struct idesc
{
1597 fep
= netdev_priv(dev
);
1598 b
= (fep
->index
) ? 128 : 64;
1600 /* Setup interrupt handlers. */
1601 for (idp
= id
; idp
->name
; idp
++) {
1602 if (request_irq(b
+idp
->irq
, fec_enet_interrupt
, IRQF_DISABLED
, idp
->name
,dev
) != 0)
1603 printk("FEC: Could not allocate %s IRQ(%d)!\n",
1604 idp
->name
, b
+idp
->irq
);
1607 /* Unmask interrupts */
1608 MCF_INTC0_ICR36
= 0x2;
1609 MCF_INTC0_ICR37
= 0x2;
1610 MCF_INTC0_ICR38
= 0x2;
1611 MCF_INTC0_ICR39
= 0x2;
1612 MCF_INTC0_ICR40
= 0x2;
1613 MCF_INTC0_ICR41
= 0x2;
1614 MCF_INTC0_ICR42
= 0x2;
1615 MCF_INTC0_ICR43
= 0x2;
1616 MCF_INTC0_ICR44
= 0x2;
1617 MCF_INTC0_ICR45
= 0x2;
1618 MCF_INTC0_ICR46
= 0x2;
1619 MCF_INTC0_ICR47
= 0x2;
1620 MCF_INTC0_ICR48
= 0x2;
1622 MCF_INTC0_IMRH
&= ~(
1623 MCF_INTC_IMRH_INT_MASK36
|
1624 MCF_INTC_IMRH_INT_MASK37
|
1625 MCF_INTC_IMRH_INT_MASK38
|
1626 MCF_INTC_IMRH_INT_MASK39
|
1627 MCF_INTC_IMRH_INT_MASK40
|
1628 MCF_INTC_IMRH_INT_MASK41
|
1629 MCF_INTC_IMRH_INT_MASK42
|
1630 MCF_INTC_IMRH_INT_MASK43
|
1631 MCF_INTC_IMRH_INT_MASK44
|
1632 MCF_INTC_IMRH_INT_MASK45
|
1633 MCF_INTC_IMRH_INT_MASK46
|
1634 MCF_INTC_IMRH_INT_MASK47
|
1635 MCF_INTC_IMRH_INT_MASK48
);
1637 /* Set up gpio outputs for MII lines */
1638 MCF_GPIO_PAR_FECI2C
|= (0 |
1639 MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC
|
1640 MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO
);
1641 MCF_GPIO_PAR_FEC
= (0 |
1642 MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC
|
1643 MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC
);
1646 static void __inline__
fec_set_mii(struct net_device
*dev
, struct fec_enet_private
*fep
)
1648 volatile fec_t
*fecp
;
1651 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;
1652 fecp
->fec_x_cntrl
= 0x00;
1655 * Set MII speed to 2.5 MHz
1657 fep
->phy_speed
= ((((MCF_CLK
/ 2) / (2500000 / 10)) + 5) / 10) * 2;
1658 fecp
->fec_mii_speed
= fep
->phy_speed
;
1660 fec_restart(dev
, 0);
1663 static void __inline__
fec_get_mac(struct net_device
*dev
)
1665 struct fec_enet_private
*fep
= netdev_priv(dev
);
1666 volatile fec_t
*fecp
;
1667 unsigned char *iap
, tmpaddr
[ETH_ALEN
];
1673 * Get MAC address from FLASH.
1674 * If it is all 1's or 0's, use the default.
1677 if ((iap
[0] == 0) && (iap
[1] == 0) && (iap
[2] == 0) &&
1678 (iap
[3] == 0) && (iap
[4] == 0) && (iap
[5] == 0))
1679 iap
= fec_mac_default
;
1680 if ((iap
[0] == 0xff) && (iap
[1] == 0xff) && (iap
[2] == 0xff) &&
1681 (iap
[3] == 0xff) && (iap
[4] == 0xff) && (iap
[5] == 0xff))
1682 iap
= fec_mac_default
;
1684 *((unsigned long *) &tmpaddr
[0]) = fecp
->fec_addr_low
;
1685 *((unsigned short *) &tmpaddr
[4]) = (fecp
->fec_addr_high
>> 16);
1689 memcpy(dev
->dev_addr
, iap
, ETH_ALEN
);
1691 /* Adjust MAC if using default MAC address */
1692 if (iap
== fec_mac_default
)
1693 dev
->dev_addr
[ETH_ALEN
-1] = fec_mac_default
[ETH_ALEN
-1] + fep
->index
;
1696 static void __inline__
fec_disable_phy_intr(void)
1700 static void __inline__
fec_phy_ack_intr(void)
1706 /* ------------------------------------------------------------------------- */
1708 static void mii_display_status(struct net_device
*dev
)
1710 struct fec_enet_private
*fep
= netdev_priv(dev
);
1711 volatile uint
*s
= &(fep
->phy_status
);
1713 if (!fep
->link
&& !fep
->old_link
) {
1714 /* Link is still down - don't print anything */
1718 printk("%s: status: ", dev
->name
);
1721 printk("link down");
1725 switch(*s
& PHY_STAT_SPMASK
) {
1726 case PHY_STAT_100FDX
: printk(", 100MBit Full Duplex"); break;
1727 case PHY_STAT_100HDX
: printk(", 100MBit Half Duplex"); break;
1728 case PHY_STAT_10FDX
: printk(", 10MBit Full Duplex"); break;
1729 case PHY_STAT_10HDX
: printk(", 10MBit Half Duplex"); break;
1731 printk(", Unknown speed/duplex");
1734 if (*s
& PHY_STAT_ANC
)
1735 printk(", auto-negotiation complete");
1738 if (*s
& PHY_STAT_FAULT
)
1739 printk(", remote fault");
1744 static void mii_display_config(struct work_struct
*work
)
1746 struct fec_enet_private
*fep
= container_of(work
, struct fec_enet_private
, phy_task
);
1747 struct net_device
*dev
= fep
->netdev
;
1748 uint status
= fep
->phy_status
;
1751 ** When we get here, phy_task is already removed from
1752 ** the workqueue. It is thus safe to allow to reuse it.
1754 fep
->mii_phy_task_queued
= 0;
1755 printk("%s: config: auto-negotiation ", dev
->name
);
1757 if (status
& PHY_CONF_ANE
)
1762 if (status
& PHY_CONF_100FDX
)
1764 if (status
& PHY_CONF_100HDX
)
1766 if (status
& PHY_CONF_10FDX
)
1768 if (status
& PHY_CONF_10HDX
)
1770 if (!(status
& PHY_CONF_SPMASK
))
1771 printk(", No speed/duplex selected?");
1773 if (status
& PHY_CONF_LOOP
)
1774 printk(", loopback enabled");
1778 fep
->sequence_done
= 1;
1781 static void mii_relink(struct work_struct
*work
)
1783 struct fec_enet_private
*fep
= container_of(work
, struct fec_enet_private
, phy_task
);
1784 struct net_device
*dev
= fep
->netdev
;
1788 ** When we get here, phy_task is already removed from
1789 ** the workqueue. It is thus safe to allow to reuse it.
1791 fep
->mii_phy_task_queued
= 0;
1792 fep
->link
= (fep
->phy_status
& PHY_STAT_LINK
) ? 1 : 0;
1793 mii_display_status(dev
);
1794 fep
->old_link
= fep
->link
;
1799 & (PHY_STAT_100FDX
| PHY_STAT_10FDX
))
1801 fec_restart(dev
, duplex
);
1806 enable_irq(fep
->mii_irq
);
1811 /* mii_queue_relink is called in interrupt context from mii_link_interrupt */
1812 static void mii_queue_relink(uint mii_reg
, struct net_device
*dev
)
1814 struct fec_enet_private
*fep
= netdev_priv(dev
);
1817 ** We cannot queue phy_task twice in the workqueue. It
1818 ** would cause an endless loop in the workqueue.
1819 ** Fortunately, if the last mii_relink entry has not yet been
1820 ** executed now, it will do the job for the current interrupt,
1821 ** which is just what we want.
1823 if (fep
->mii_phy_task_queued
)
1826 fep
->mii_phy_task_queued
= 1;
1827 INIT_WORK(&fep
->phy_task
, mii_relink
);
1828 schedule_work(&fep
->phy_task
);
1831 /* mii_queue_config is called in interrupt context from fec_enet_mii */
1832 static void mii_queue_config(uint mii_reg
, struct net_device
*dev
)
1834 struct fec_enet_private
*fep
= netdev_priv(dev
);
1836 if (fep
->mii_phy_task_queued
)
1839 fep
->mii_phy_task_queued
= 1;
1840 INIT_WORK(&fep
->phy_task
, mii_display_config
);
1841 schedule_work(&fep
->phy_task
);
1844 phy_cmd_t
const phy_cmd_relink
[] = {
1845 { mk_mii_read(MII_REG_CR
), mii_queue_relink
},
1848 phy_cmd_t
const phy_cmd_config
[] = {
1849 { mk_mii_read(MII_REG_CR
), mii_queue_config
},
1853 /* Read remainder of PHY ID.
1856 mii_discover_phy3(uint mii_reg
, struct net_device
*dev
)
1858 struct fec_enet_private
*fep
;
1861 fep
= netdev_priv(dev
);
1862 fep
->phy_id
|= (mii_reg
& 0xffff);
1863 printk("fec: PHY @ 0x%x, ID 0x%08x", fep
->phy_addr
, fep
->phy_id
);
1865 for(i
= 0; phy_info
[i
]; i
++) {
1866 if(phy_info
[i
]->id
== (fep
->phy_id
>> 4))
1871 printk(" -- %s\n", phy_info
[i
]->name
);
1873 printk(" -- unknown PHY!\n");
1875 fep
->phy
= phy_info
[i
];
1876 fep
->phy_id_done
= 1;
1879 /* Scan all of the MII PHY addresses looking for someone to respond
1880 * with a valid ID. This usually happens quickly.
1883 mii_discover_phy(uint mii_reg
, struct net_device
*dev
)
1885 struct fec_enet_private
*fep
;
1886 volatile fec_t
*fecp
;
1889 fep
= netdev_priv(dev
);
1892 if (fep
->phy_addr
< 32) {
1893 if ((phytype
= (mii_reg
& 0xffff)) != 0xffff && phytype
!= 0) {
1895 /* Got first part of ID, now get remainder.
1897 fep
->phy_id
= phytype
<< 16;
1898 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR2
),
1902 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
),
1906 printk("FEC: No PHY device found.\n");
1907 /* Disable external MII interface */
1908 fecp
->fec_mii_speed
= fep
->phy_speed
= 0;
1909 fec_disable_phy_intr();
1913 /* This interrupt occurs when the PHY detects a link change.
1915 #ifdef HAVE_mii_link_interrupt
1917 mii_link_interrupt(int irq
, void * dev_id
)
1919 struct net_device
*dev
= dev_id
;
1920 struct fec_enet_private
*fep
= netdev_priv(dev
);
1925 disable_irq(fep
->mii_irq
); /* disable now, enable later */
1928 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1929 mii_do_cmd(dev
, phy_cmd_relink
); /* restart and display status */
1936 fec_enet_open(struct net_device
*dev
)
1938 struct fec_enet_private
*fep
= netdev_priv(dev
);
1940 /* I should reset the ring buffers here, but I don't yet know
1941 * a simple way to do that.
1943 fec_set_mac_address(dev
);
1945 fep
->sequence_done
= 0;
1949 mii_do_cmd(dev
, fep
->phy
->ack_int
);
1950 mii_do_cmd(dev
, fep
->phy
->config
);
1951 mii_do_cmd(dev
, phy_cmd_config
); /* display configuration */
1953 /* Poll until the PHY tells us its configuration
1955 * Request is initiated by mii_do_cmd above, but answer
1956 * comes by interrupt.
1957 * This should take about 25 usec per register at 2.5 MHz,
1958 * and we read approximately 5 registers.
1960 while(!fep
->sequence_done
)
1963 mii_do_cmd(dev
, fep
->phy
->startup
);
1965 /* Set the initial link state to true. A lot of hardware
1966 * based on this device does not implement a PHY interrupt,
1967 * so we are never notified of link change.
1971 fep
->link
= 1; /* lets just try it and see */
1972 /* no phy, go full duplex, it's most likely a hub chip */
1973 fec_restart(dev
, 1);
1976 netif_start_queue(dev
);
1978 return 0; /* Success */
1982 fec_enet_close(struct net_device
*dev
)
1984 struct fec_enet_private
*fep
= netdev_priv(dev
);
1986 /* Don't know what to do yet.
1989 netif_stop_queue(dev
);
1995 /* Set or clear the multicast filter for this adaptor.
1996 * Skeleton taken from sunlance driver.
1997 * The CPM Ethernet implementation allows Multicast as well as individual
1998 * MAC address filtering. Some of the drivers check to make sure it is
1999 * a group multicast address, and discard those that are not. I guess I
2000 * will do the same for now, but just remove the test if you want
2001 * individual filtering as well (do the upper net layers want or support
2002 * this kind of feature?).
2005 #define HASH_BITS 6 /* #bits in hash */
2006 #define CRC32_POLY 0xEDB88320
2008 static void set_multicast_list(struct net_device
*dev
)
2010 struct fec_enet_private
*fep
;
2012 struct dev_mc_list
*dmi
;
2013 unsigned int i
, j
, bit
, data
, crc
;
2016 fep
= netdev_priv(dev
);
2019 if (dev
->flags
&IFF_PROMISC
) {
2020 ep
->fec_r_cntrl
|= 0x0008;
2023 ep
->fec_r_cntrl
&= ~0x0008;
2025 if (dev
->flags
& IFF_ALLMULTI
) {
2026 /* Catch all multicast addresses, so set the
2027 * filter to all 1's.
2029 ep
->fec_grp_hash_table_high
= 0xffffffff;
2030 ep
->fec_grp_hash_table_low
= 0xffffffff;
2032 /* Clear filter and add the addresses in hash register.
2034 ep
->fec_grp_hash_table_high
= 0;
2035 ep
->fec_grp_hash_table_low
= 0;
2039 for (j
= 0; j
< dev
->mc_count
; j
++, dmi
= dmi
->next
)
2041 /* Only support group multicast for now.
2043 if (!(dmi
->dmi_addr
[0] & 1))
2046 /* calculate crc32 value of mac address
2050 for (i
= 0; i
< dmi
->dmi_addrlen
; i
++)
2052 data
= dmi
->dmi_addr
[i
];
2053 for (bit
= 0; bit
< 8; bit
++, data
>>= 1)
2056 (((crc
^ data
) & 1) ? CRC32_POLY
: 0);
2060 /* only upper 6 bits (HASH_BITS) are used
2061 which point to specific bit in he hash registers
2063 hash
= (crc
>> (32 - HASH_BITS
)) & 0x3f;
2066 ep
->fec_grp_hash_table_high
|= 1 << (hash
- 32);
2068 ep
->fec_grp_hash_table_low
|= 1 << hash
;
2074 /* Set a MAC change in hardware.
2077 fec_set_mac_address(struct net_device
*dev
)
2079 volatile fec_t
*fecp
;
2081 fecp
= ((struct fec_enet_private
*)netdev_priv(dev
))->hwp
;
2083 /* Set station address. */
2084 fecp
->fec_addr_low
= dev
->dev_addr
[3] | (dev
->dev_addr
[2] << 8) |
2085 (dev
->dev_addr
[1] << 16) | (dev
->dev_addr
[0] << 24);
2086 fecp
->fec_addr_high
= (dev
->dev_addr
[5] << 16) |
2087 (dev
->dev_addr
[4] << 24);
2091 /* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
2094 * XXX: We need to clean up on failure exits here.
2096 int __init
fec_enet_init(struct net_device
*dev
)
2098 struct fec_enet_private
*fep
= netdev_priv(dev
);
2099 unsigned long mem_addr
;
2100 volatile cbd_t
*bdp
;
2102 volatile fec_t
*fecp
;
2104 static int index
= 0;
2106 /* Only allow us to be probed once. */
2107 if (index
>= FEC_MAX_PORTS
)
2110 /* Allocate memory for buffer descriptors.
2112 mem_addr
= __get_free_page(GFP_KERNEL
);
2113 if (mem_addr
== 0) {
2114 printk("FEC: allocate descriptor memory failed?\n");
2118 spin_lock_init(&fep
->hw_lock
);
2119 spin_lock_init(&fep
->mii_lock
);
2121 /* Create an Ethernet device instance.
2123 fecp
= (volatile fec_t
*) fec_hw
[index
];
2129 /* Whack a reset. We should wait for this.
2131 fecp
->fec_ecntrl
= 1;
2134 /* Set the Ethernet address. If using multiple Enets on the 8xx,
2135 * this needs some work to get unique addresses.
2137 * This is our default MAC address unless the user changes
2138 * it via eth_mac_addr (our dev->set_mac_addr handler).
2142 cbd_base
= (cbd_t
*)mem_addr
;
2143 /* XXX: missing check for allocation failure */
2145 /* Set receive and transmit descriptor base.
2147 fep
->rx_bd_base
= cbd_base
;
2148 fep
->tx_bd_base
= cbd_base
+ RX_RING_SIZE
;
2150 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
2151 fep
->cur_rx
= fep
->rx_bd_base
;
2153 fep
->skb_cur
= fep
->skb_dirty
= 0;
2155 /* Initialize the receive buffer descriptors.
2157 bdp
= fep
->rx_bd_base
;
2158 for (i
=0; i
<FEC_ENET_RX_PAGES
; i
++) {
2162 mem_addr
= __get_free_page(GFP_KERNEL
);
2163 /* XXX: missing check for allocation failure */
2165 /* Initialize the BD for every fragment in the page.
2167 for (j
=0; j
<FEC_ENET_RX_FRPPG
; j
++) {
2168 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
2169 bdp
->cbd_bufaddr
= __pa(mem_addr
);
2170 mem_addr
+= FEC_ENET_RX_FRSIZE
;
2175 /* Set the last buffer to wrap.
2178 bdp
->cbd_sc
|= BD_SC_WRAP
;
2180 /* ...and the same for transmmit.
2182 bdp
= fep
->tx_bd_base
;
2183 for (i
=0, j
=FEC_ENET_TX_FRPPG
; i
<TX_RING_SIZE
; i
++) {
2184 if (j
>= FEC_ENET_TX_FRPPG
) {
2185 mem_addr
= __get_free_page(GFP_KERNEL
);
2188 mem_addr
+= FEC_ENET_TX_FRSIZE
;
2191 fep
->tx_bounce
[i
] = (unsigned char *) mem_addr
;
2193 /* Initialize the BD for every fragment in the page.
2196 bdp
->cbd_bufaddr
= 0;
2200 /* Set the last buffer to wrap.
2203 bdp
->cbd_sc
|= BD_SC_WRAP
;
2205 /* Set receive and transmit descriptor base.
2207 fecp
->fec_r_des_start
= __pa((uint
)(fep
->rx_bd_base
));
2208 fecp
->fec_x_des_start
= __pa((uint
)(fep
->tx_bd_base
));
2210 /* Install our interrupt handlers. This varies depending on
2213 fec_request_intrs(dev
);
2215 fecp
->fec_grp_hash_table_high
= 0;
2216 fecp
->fec_grp_hash_table_low
= 0;
2217 fecp
->fec_r_buff_size
= PKT_MAXBLR_SIZE
;
2218 fecp
->fec_ecntrl
= 2;
2219 fecp
->fec_r_des_active
= 0;
2220 #ifndef CONFIG_M5272
2221 fecp
->fec_hash_table_high
= 0;
2222 fecp
->fec_hash_table_low
= 0;
2225 dev
->base_addr
= (unsigned long)fecp
;
2227 /* The FEC Ethernet specific entries in the device structure. */
2228 dev
->open
= fec_enet_open
;
2229 dev
->hard_start_xmit
= fec_enet_start_xmit
;
2230 dev
->tx_timeout
= fec_timeout
;
2231 dev
->watchdog_timeo
= TX_TIMEOUT
;
2232 dev
->stop
= fec_enet_close
;
2233 dev
->set_multicast_list
= set_multicast_list
;
2235 for (i
=0; i
<NMII
-1; i
++)
2236 mii_cmds
[i
].mii_next
= &mii_cmds
[i
+1];
2237 mii_free
= mii_cmds
;
2239 /* setup MII interface */
2240 fec_set_mii(dev
, fep
);
2242 /* Clear and enable interrupts */
2243 fecp
->fec_ievent
= 0xffc00000;
2244 fecp
->fec_imask
= (FEC_ENET_TXF
| FEC_ENET_RXF
| FEC_ENET_MII
);
2246 /* Queue up command to detect the PHY and initialize the
2247 * remainder of the interface.
2249 fep
->phy_id_done
= 0;
2251 mii_queue(dev
, mk_mii_read(MII_REG_PHYIR1
), mii_discover_phy
);
2257 /* This function is called to start or restart the FEC during a link
2258 * change. This only happens when switching between half and full
2262 fec_restart(struct net_device
*dev
, int duplex
)
2264 struct fec_enet_private
*fep
;
2265 volatile cbd_t
*bdp
;
2266 volatile fec_t
*fecp
;
2269 fep
= netdev_priv(dev
);
2272 /* Whack a reset. We should wait for this.
2274 fecp
->fec_ecntrl
= 1;
2277 /* Clear any outstanding interrupt.
2279 fecp
->fec_ievent
= 0xffc00000;
2281 /* Set station address.
2283 fec_set_mac_address(dev
);
2285 /* Reset all multicast.
2287 fecp
->fec_grp_hash_table_high
= 0;
2288 fecp
->fec_grp_hash_table_low
= 0;
2290 /* Set maximum receive buffer size.
2292 fecp
->fec_r_buff_size
= PKT_MAXBLR_SIZE
;
2294 /* Set receive and transmit descriptor base.
2296 fecp
->fec_r_des_start
= __pa((uint
)(fep
->rx_bd_base
));
2297 fecp
->fec_x_des_start
= __pa((uint
)(fep
->tx_bd_base
));
2299 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
2300 fep
->cur_rx
= fep
->rx_bd_base
;
2302 /* Reset SKB transmit buffers.
2304 fep
->skb_cur
= fep
->skb_dirty
= 0;
2305 for (i
=0; i
<=TX_RING_MOD_MASK
; i
++) {
2306 if (fep
->tx_skbuff
[i
] != NULL
) {
2307 dev_kfree_skb_any(fep
->tx_skbuff
[i
]);
2308 fep
->tx_skbuff
[i
] = NULL
;
2312 /* Initialize the receive buffer descriptors.
2314 bdp
= fep
->rx_bd_base
;
2315 for (i
=0; i
<RX_RING_SIZE
; i
++) {
2317 /* Initialize the BD for every fragment in the page.
2319 bdp
->cbd_sc
= BD_ENET_RX_EMPTY
;
2323 /* Set the last buffer to wrap.
2326 bdp
->cbd_sc
|= BD_SC_WRAP
;
2328 /* ...and the same for transmmit.
2330 bdp
= fep
->tx_bd_base
;
2331 for (i
=0; i
<TX_RING_SIZE
; i
++) {
2333 /* Initialize the BD for every fragment in the page.
2336 bdp
->cbd_bufaddr
= 0;
2340 /* Set the last buffer to wrap.
2343 bdp
->cbd_sc
|= BD_SC_WRAP
;
2348 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x04;/* MII enable */
2349 fecp
->fec_x_cntrl
= 0x04; /* FD enable */
2351 /* MII enable|No Rcv on Xmit */
2352 fecp
->fec_r_cntrl
= OPT_FRAME_SIZE
| 0x06;
2353 fecp
->fec_x_cntrl
= 0x00;
2355 fep
->full_duplex
= duplex
;
2359 fecp
->fec_mii_speed
= fep
->phy_speed
;
2361 /* And last, enable the transmit and receive processing.
2363 fecp
->fec_ecntrl
= 2;
2364 fecp
->fec_r_des_active
= 0;
2366 /* Enable interrupts we wish to service.
2368 fecp
->fec_imask
= (FEC_ENET_TXF
| FEC_ENET_RXF
| FEC_ENET_MII
);
2372 fec_stop(struct net_device
*dev
)
2374 volatile fec_t
*fecp
;
2375 struct fec_enet_private
*fep
;
2377 fep
= netdev_priv(dev
);
2381 ** We cannot expect a graceful transmit stop without link !!!
2385 fecp
->fec_x_cntrl
= 0x01; /* Graceful transmit stop */
2387 if (!(fecp
->fec_ievent
& FEC_ENET_GRA
))
2388 printk("fec_stop : Graceful transmit stop did not complete !\n");
2391 /* Whack a reset. We should wait for this.
2393 fecp
->fec_ecntrl
= 1;
2396 /* Clear outstanding MII command interrupts.
2398 fecp
->fec_ievent
= FEC_ENET_MII
;
2400 fecp
->fec_imask
= FEC_ENET_MII
;
2401 fecp
->fec_mii_speed
= fep
->phy_speed
;
2404 static int __init
fec_enet_module_init(void)
2406 struct net_device
*dev
;
2409 printk("FEC ENET Version 0.2\n");
2411 for (i
= 0; (i
< FEC_MAX_PORTS
); i
++) {
2412 dev
= alloc_etherdev(sizeof(struct fec_enet_private
));
2415 err
= fec_enet_init(dev
);
2420 if (register_netdev(dev
) != 0) {
2421 /* XXX: missing cleanup here */
2426 printk("%s: ethernet %pM\n", dev
->name
, dev
->dev_addr
);
2431 module_init(fec_enet_module_init
);
2433 MODULE_LICENSE("GPL");