2 * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
7 * Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
8 * and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
10 * Released under the GPL
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/string.h>
17 #include <linux/ptrace.h>
18 #include <linux/errno.h>
19 #include <linux/ioport.h>
20 #include <linux/slab.h>
21 #include <linux/interrupt.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/spinlock.h>
28 #include <linux/mii.h>
29 #include <linux/ethtool.h>
30 #include <linux/bitops.h>
31 #include <linux/dma-mapping.h>
33 #include <asm/8xx_immap.h>
34 #include <asm/pgtable.h>
35 #include <asm/mpc8xx.h>
37 #include <asm/uaccess.h>
38 #include <asm/commproc.h>
42 /*************************************************/
44 #define FEC_MAX_MULTICAST_ADDRS 64
46 /*************************************************/
48 static char version
[] __devinitdata
=
49 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")" "\n";
51 MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>");
52 MODULE_DESCRIPTION("Motorola 8xx FEC ethernet driver");
53 MODULE_LICENSE("GPL");
55 int fec_8xx_debug
= -1; /* -1 == use FEC_8XX_DEF_MSG_ENABLE as value */
56 module_param(fec_8xx_debug
, int, 0);
57 MODULE_PARM_DESC(fec_8xx_debug
,
58 "FEC 8xx bitmapped debugging message enable value");
61 /*************************************************/
64 * Delay to wait for FEC reset command to complete (in us)
66 #define FEC_RESET_DELAY 50
68 /*****************************************************************************************/
70 static void fec_whack_reset(fec_t
* fecp
)
75 * Whack a reset. We should wait for this.
77 FW(fecp
, ecntrl
, FEC_ECNTRL_PINMUX
| FEC_ECNTRL_RESET
);
79 (FR(fecp
, ecntrl
) & FEC_ECNTRL_RESET
) != 0 && i
< FEC_RESET_DELAY
;
83 if (i
== FEC_RESET_DELAY
)
84 printk(KERN_WARNING
"FEC Reset timeout!\n");
88 /****************************************************************************/
91 * Transmitter timeout.
93 #define TX_TIMEOUT (2*HZ)
95 /****************************************************************************/
98 * Returns the CRC needed when filling in the hash table for
99 * multicast group filtering
100 * pAddr must point to a MAC address (6 bytes)
102 static __u32
fec_mulicast_calc_crc(char *pAddr
)
107 __u32 crc
= 0xffffffff;
110 for (byte_count
= 0; byte_count
< 6; byte_count
++) {
111 byte
= pAddr
[byte_count
];
112 for (bit_count
= 0; bit_count
< 8; bit_count
++) {
115 if (msb
^ (byte
& 0x1)) {
125 * Set or clear the multicast filter for this adaptor.
126 * Skeleton taken from sunlance driver.
127 * The CPM Ethernet implementation allows Multicast as well as individual
128 * MAC address filtering. Some of the drivers check to make sure it is
129 * a group multicast address, and discard those that are not. I guess I
130 * will do the same for now, but just remove the test if you want
131 * individual filtering as well (do the upper net layers want or support
132 * this kind of feature?).
134 static void fec_set_multicast_list(struct net_device
*dev
)
136 struct fec_enet_private
*fep
= netdev_priv(dev
);
137 fec_t
*fecp
= fep
->fecp
;
138 struct dev_mc_list
*pmc
;
147 if ((dev
->flags
& IFF_PROMISC
) != 0) {
149 spin_lock_irqsave(&fep
->lock
, flags
);
150 FS(fecp
, r_cntrl
, FEC_RCNTRL_PROM
);
151 spin_unlock_irqrestore(&fep
->lock
, flags
);
156 printk(KERN_WARNING DRV_MODULE_NAME
157 ": %s: Promiscuous mode enabled.\n", dev
->name
);
162 if ((dev
->flags
& IFF_ALLMULTI
) != 0 ||
163 dev
->mc_count
> FEC_MAX_MULTICAST_ADDRS
) {
165 * Catch all multicast addresses, set the filter to all 1's.
174 * Now populate the hash table
176 for (pmc
= dev
->mc_list
; pmc
!= NULL
; pmc
= pmc
->next
) {
177 crc
= fec_mulicast_calc_crc(pmc
->dmi_addr
);
178 temp
= (crc
& 0x3f) >> 1;
179 hash_index
= ((temp
& 0x01) << 4) |
180 ((temp
& 0x02) << 2) |
182 ((temp
& 0x08) >> 2) |
183 ((temp
& 0x10) >> 4);
184 csrVal
= (1 << hash_index
);
192 spin_lock_irqsave(&fep
->lock
, flags
);
193 FC(fecp
, r_cntrl
, FEC_RCNTRL_PROM
);
194 FW(fecp
, hash_table_high
, hthi
);
195 FW(fecp
, hash_table_low
, htlo
);
196 spin_unlock_irqrestore(&fep
->lock
, flags
);
199 static int fec_set_mac_address(struct net_device
*dev
, void *addr
)
201 struct sockaddr
*mac
= addr
;
202 struct fec_enet_private
*fep
= netdev_priv(dev
);
203 struct fec
*fecp
= fep
->fecp
;
205 __u32 addrhi
, addrlo
;
208 /* Get pointer to SCC area in parameter RAM. */
209 for (i
= 0; i
< 6; i
++)
210 dev
->dev_addr
[i
] = mac
->sa_data
[i
];
213 * Set station address.
215 addrhi
= ((__u32
) dev
->dev_addr
[0] << 24) |
216 ((__u32
) dev
->dev_addr
[1] << 16) |
217 ((__u32
) dev
->dev_addr
[2] << 8) |
218 (__u32
) dev
->dev_addr
[3];
219 addrlo
= ((__u32
) dev
->dev_addr
[4] << 24) |
220 ((__u32
) dev
->dev_addr
[5] << 16);
222 spin_lock_irqsave(&fep
->lock
, flags
);
223 FW(fecp
, addr_low
, addrhi
);
224 FW(fecp
, addr_high
, addrlo
);
225 spin_unlock_irqrestore(&fep
->lock
, flags
);
231 * This function is called to start or restart the FEC during a link
232 * change. This only happens when switching between half and full
235 void fec_restart(struct net_device
*dev
, int duplex
, int speed
)
238 immap_t
*immap
= (immap_t
*) IMAP_ADDR
;
241 struct fec_enet_private
*fep
= netdev_priv(dev
);
242 struct fec
*fecp
= fep
->fecp
;
243 const struct fec_platform_info
*fpi
= fep
->fpi
;
247 __u32 addrhi
, addrlo
;
249 fec_whack_reset(fep
->fecp
);
252 * Set station address.
254 addrhi
= ((__u32
) dev
->dev_addr
[0] << 24) |
255 ((__u32
) dev
->dev_addr
[1] << 16) |
256 ((__u32
) dev
->dev_addr
[2] << 8) |
257 (__u32
) dev
->dev_addr
[3];
258 addrlo
= ((__u32
) dev
->dev_addr
[4] << 24) |
259 ((__u32
) dev
->dev_addr
[5] << 16);
260 FW(fecp
, addr_low
, addrhi
);
261 FW(fecp
, addr_high
, addrlo
);
264 * Reset all multicast.
266 FW(fecp
, hash_table_high
, 0);
267 FW(fecp
, hash_table_low
, 0);
270 * Set maximum receive buffer size.
272 FW(fecp
, r_buff_size
, PKT_MAXBLR_SIZE
);
273 FW(fecp
, r_hash
, PKT_MAXBUF_SIZE
);
276 * Set receive and transmit descriptor base.
278 FW(fecp
, r_des_start
, iopa((__u32
) (fep
->rx_bd_base
)));
279 FW(fecp
, x_des_start
, iopa((__u32
) (fep
->tx_bd_base
)));
281 fep
->dirty_tx
= fep
->cur_tx
= fep
->tx_bd_base
;
282 fep
->tx_free
= fep
->tx_ring
;
283 fep
->cur_rx
= fep
->rx_bd_base
;
286 * Reset SKB receive buffers
288 for (i
= 0; i
< fep
->rx_ring
; i
++) {
289 if ((skb
= fep
->rx_skbuff
[i
]) == NULL
)
291 fep
->rx_skbuff
[i
] = NULL
;
296 * Initialize the receive buffer descriptors.
298 for (i
= 0, bdp
= fep
->rx_bd_base
; i
< fep
->rx_ring
; i
++, bdp
++) {
299 skb
= dev_alloc_skb(ENET_RX_FRSIZE
);
301 printk(KERN_WARNING DRV_MODULE_NAME
302 ": %s Memory squeeze, unable to allocate skb\n",
304 fep
->stats
.rx_dropped
++;
307 fep
->rx_skbuff
[i
] = skb
;
309 CBDW_BUFADDR(bdp
, dma_map_single(NULL
, skb
->data
,
310 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE
),
312 CBDW_DATLEN(bdp
, 0); /* zero */
313 CBDW_SC(bdp
, BD_ENET_RX_EMPTY
|
314 ((i
< fep
->rx_ring
- 1) ? 0 : BD_SC_WRAP
));
317 * if we failed, fillup remainder
319 for (; i
< fep
->rx_ring
; i
++, bdp
++) {
320 fep
->rx_skbuff
[i
] = NULL
;
321 CBDW_SC(bdp
, (i
< fep
->rx_ring
- 1) ? 0 : BD_SC_WRAP
);
325 * Reset SKB transmit buffers.
327 for (i
= 0; i
< fep
->tx_ring
; i
++) {
328 if ((skb
= fep
->tx_skbuff
[i
]) == NULL
)
330 fep
->tx_skbuff
[i
] = NULL
;
335 * ...and the same for transmit.
337 for (i
= 0, bdp
= fep
->tx_bd_base
; i
< fep
->tx_ring
; i
++, bdp
++) {
338 fep
->tx_skbuff
[i
] = NULL
;
339 CBDW_BUFADDR(bdp
, virt_to_bus(NULL
));
341 CBDW_SC(bdp
, (i
< fep
->tx_ring
- 1) ? 0 : BD_SC_WRAP
);
345 * Enable big endian and don't care about SDMA FC.
347 FW(fecp
, fun_code
, 0x78000000);
352 FW(fecp
, mii_speed
, fep
->fec_phy_speed
);
355 * Clear any outstanding interrupt.
357 FW(fecp
, ievent
, 0xffc0);
358 FW(fecp
, ivec
, (fpi
->fec_irq
/ 2) << 29);
361 * adjust to speed (only for DUET & RMII)
364 cptr
= in_be32(&immap
->im_cpm
.cp_cptr
);
365 switch (fpi
->fec_no
) {
368 * check if in RMII mode
370 if ((cptr
& 0x100) == 0)
375 else if (speed
== 100)
380 * check if in RMII mode
382 if ((cptr
& 0x80) == 0)
387 else if (speed
== 100)
393 out_be32(&immap
->im_cpm
.cp_cptr
, cptr
);
396 FW(fecp
, r_cntrl
, FEC_RCNTRL_MII_MODE
); /* MII enable */
398 * adjust to duplex mode
401 FC(fecp
, r_cntrl
, FEC_RCNTRL_DRT
);
402 FS(fecp
, x_cntrl
, FEC_TCNTRL_FDEN
); /* FD enable */
404 FS(fecp
, r_cntrl
, FEC_RCNTRL_DRT
);
405 FC(fecp
, x_cntrl
, FEC_TCNTRL_FDEN
); /* FD disable */
409 * Enable interrupts we wish to service.
411 FW(fecp
, imask
, FEC_ENET_TXF
| FEC_ENET_TXB
|
412 FEC_ENET_RXF
| FEC_ENET_RXB
);
415 * And last, enable the transmit and receive processing.
417 FW(fecp
, ecntrl
, FEC_ECNTRL_PINMUX
| FEC_ECNTRL_ETHER_EN
);
418 FW(fecp
, r_des_active
, 0x01000000);
421 void fec_stop(struct net_device
*dev
)
423 struct fec_enet_private
*fep
= netdev_priv(dev
);
424 fec_t
*fecp
= fep
->fecp
;
428 if ((FR(fecp
, ecntrl
) & FEC_ECNTRL_ETHER_EN
) == 0)
429 return; /* already down */
431 FW(fecp
, x_cntrl
, 0x01); /* Graceful transmit stop */
432 for (i
= 0; ((FR(fecp
, ievent
) & 0x10000000) == 0) &&
433 i
< FEC_RESET_DELAY
; i
++)
436 if (i
== FEC_RESET_DELAY
)
437 printk(KERN_WARNING DRV_MODULE_NAME
438 ": %s FEC timeout on graceful transmit stop\n",
441 * Disable FEC. Let only MII interrupts.
444 FW(fecp
, ecntrl
, ~FEC_ECNTRL_ETHER_EN
);
447 * Reset SKB transmit buffers.
449 for (i
= 0; i
< fep
->tx_ring
; i
++) {
450 if ((skb
= fep
->tx_skbuff
[i
]) == NULL
)
452 fep
->tx_skbuff
[i
] = NULL
;
457 * Reset SKB receive buffers
459 for (i
= 0; i
< fep
->rx_ring
; i
++) {
460 if ((skb
= fep
->rx_skbuff
[i
]) == NULL
)
462 fep
->rx_skbuff
[i
] = NULL
;
467 /* common receive function */
468 static int fec_enet_rx_common(struct net_device
*dev
, int *budget
)
470 struct fec_enet_private
*fep
= netdev_priv(dev
);
471 fec_t
*fecp
= fep
->fecp
;
472 const struct fec_platform_info
*fpi
= fep
->fpi
;
474 struct sk_buff
*skb
, *skbn
, *skbt
;
481 rx_work_limit
= min(dev
->quota
, *budget
);
483 if (!netif_running(dev
))
488 * First, grab all of the stats for the incoming packet.
489 * These get messed up if we get called due to a busy condition.
493 /* clear RX status bits for napi*/
495 FW(fecp
, ievent
, FEC_ENET_RXF
| FEC_ENET_RXB
);
497 while (((sc
= CBDR_SC(bdp
)) & BD_ENET_RX_EMPTY
) == 0) {
499 curidx
= bdp
- fep
->rx_bd_base
;
502 * Since we have allocated space to hold a complete frame,
503 * the last indicator should be set.
505 if ((sc
& BD_ENET_RX_LAST
) == 0)
506 printk(KERN_WARNING DRV_MODULE_NAME
507 ": %s rcv is not +last\n",
513 if (sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
| BD_ENET_RX_CL
|
514 BD_ENET_RX_NO
| BD_ENET_RX_CR
| BD_ENET_RX_OV
)) {
515 fep
->stats
.rx_errors
++;
516 /* Frame too long or too short. */
517 if (sc
& (BD_ENET_RX_LG
| BD_ENET_RX_SH
))
518 fep
->stats
.rx_length_errors
++;
519 /* Frame alignment */
520 if (sc
& (BD_ENET_RX_NO
| BD_ENET_RX_CL
))
521 fep
->stats
.rx_frame_errors
++;
523 if (sc
& BD_ENET_RX_CR
)
524 fep
->stats
.rx_crc_errors
++;
526 if (sc
& BD_ENET_RX_OV
)
527 fep
->stats
.rx_crc_errors
++;
529 skbn
= fep
->rx_skbuff
[curidx
];
530 BUG_ON(skbn
== NULL
);
534 /* napi, got packet but no quota */
535 if (fpi
->use_napi
&& --rx_work_limit
< 0)
538 skb
= fep
->rx_skbuff
[curidx
];
542 * Process the incoming frame.
544 fep
->stats
.rx_packets
++;
545 pkt_len
= CBDR_DATLEN(bdp
) - 4; /* remove CRC */
546 fep
->stats
.rx_bytes
+= pkt_len
+ 4;
548 if (pkt_len
<= fpi
->rx_copybreak
) {
549 /* +2 to make IP header L1 cache aligned */
550 skbn
= dev_alloc_skb(pkt_len
+ 2);
552 skb_reserve(skbn
, 2); /* align IP header */
553 skb_copy_from_linear_data(skb
,
562 skbn
= dev_alloc_skb(ENET_RX_FRSIZE
);
565 skb_put(skb
, pkt_len
); /* Make room */
566 skb
->protocol
= eth_type_trans(skb
, dev
);
571 netif_receive_skb(skb
);
573 printk(KERN_WARNING DRV_MODULE_NAME
574 ": %s Memory squeeze, dropping packet.\n",
576 fep
->stats
.rx_dropped
++;
581 fep
->rx_skbuff
[curidx
] = skbn
;
582 CBDW_BUFADDR(bdp
, dma_map_single(NULL
, skbn
->data
,
583 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE
),
586 CBDW_SC(bdp
, (sc
& ~BD_ENET_RX_STATS
) | BD_ENET_RX_EMPTY
);
589 * Update BD pointer to next entry.
591 if ((sc
& BD_ENET_RX_WRAP
) == 0)
594 bdp
= fep
->rx_bd_base
;
597 * Doing this here will keep the FEC running while we process
598 * incoming frames. On a heavily loaded network, we should be
599 * able to keep up at the expense of system resources.
601 FW(fecp
, r_des_active
, 0x01000000);
607 dev
->quota
-= received
;
610 if (rx_work_limit
< 0)
611 return 1; /* not done */
614 netif_rx_complete(dev
);
616 /* enable RX interrupt bits */
617 FS(fecp
, imask
, FEC_ENET_RXF
| FEC_ENET_RXB
);
623 static void fec_enet_tx(struct net_device
*dev
)
625 struct fec_enet_private
*fep
= netdev_priv(dev
);
628 int dirtyidx
, do_wake
;
631 spin_lock(&fep
->lock
);
635 while (((sc
= CBDR_SC(bdp
)) & BD_ENET_TX_READY
) == 0) {
637 dirtyidx
= bdp
- fep
->tx_bd_base
;
639 if (fep
->tx_free
== fep
->tx_ring
)
642 skb
= fep
->tx_skbuff
[dirtyidx
];
647 if (sc
& (BD_ENET_TX_HB
| BD_ENET_TX_LC
|
648 BD_ENET_TX_RL
| BD_ENET_TX_UN
| BD_ENET_TX_CSL
)) {
649 fep
->stats
.tx_errors
++;
650 if (sc
& BD_ENET_TX_HB
) /* No heartbeat */
651 fep
->stats
.tx_heartbeat_errors
++;
652 if (sc
& BD_ENET_TX_LC
) /* Late collision */
653 fep
->stats
.tx_window_errors
++;
654 if (sc
& BD_ENET_TX_RL
) /* Retrans limit */
655 fep
->stats
.tx_aborted_errors
++;
656 if (sc
& BD_ENET_TX_UN
) /* Underrun */
657 fep
->stats
.tx_fifo_errors
++;
658 if (sc
& BD_ENET_TX_CSL
) /* Carrier lost */
659 fep
->stats
.tx_carrier_errors
++;
661 fep
->stats
.tx_packets
++;
663 if (sc
& BD_ENET_TX_READY
)
664 printk(KERN_WARNING DRV_MODULE_NAME
665 ": %s HEY! Enet xmit interrupt and TX_READY.\n",
669 * Deferred means some collisions occurred during transmit,
670 * but we eventually sent the packet OK.
672 if (sc
& BD_ENET_TX_DEF
)
673 fep
->stats
.collisions
++;
676 * Free the sk buffer associated with this last transmit.
678 dev_kfree_skb_irq(skb
);
679 fep
->tx_skbuff
[dirtyidx
] = NULL
;
682 * Update pointer to next buffer descriptor to be transmitted.
684 if ((sc
& BD_ENET_TX_WRAP
) == 0)
687 bdp
= fep
->tx_bd_base
;
690 * Since we have freed up a buffer, the ring is no longer
699 spin_unlock(&fep
->lock
);
701 if (do_wake
&& netif_queue_stopped(dev
))
702 netif_wake_queue(dev
);
706 * The interrupt handler.
707 * This is called from the MPC core interrupt.
710 fec_enet_interrupt(int irq
, void *dev_id
)
712 struct net_device
*dev
= dev_id
;
713 struct fec_enet_private
*fep
;
714 const struct fec_platform_info
*fpi
;
717 __u32 int_events_napi
;
719 if (unlikely(dev
== NULL
))
722 fep
= netdev_priv(dev
);
727 * Get the interrupt events that caused us to be here.
729 while ((int_events
= FR(fecp
, ievent
) & FR(fecp
, imask
)) != 0) {
732 FW(fecp
, ievent
, int_events
);
734 int_events_napi
= int_events
& ~(FEC_ENET_RXF
| FEC_ENET_RXB
);
735 FW(fecp
, ievent
, int_events_napi
);
738 if ((int_events
& (FEC_ENET_HBERR
| FEC_ENET_BABR
|
739 FEC_ENET_BABT
| FEC_ENET_EBERR
)) != 0)
740 printk(KERN_WARNING DRV_MODULE_NAME
741 ": %s FEC ERROR(s) 0x%x\n",
742 dev
->name
, int_events
);
744 if ((int_events
& FEC_ENET_RXF
) != 0) {
746 fec_enet_rx_common(dev
, NULL
);
748 if (netif_rx_schedule_prep(dev
)) {
749 /* disable rx interrupts */
750 FC(fecp
, imask
, FEC_ENET_RXF
| FEC_ENET_RXB
);
751 __netif_rx_schedule(dev
);
753 printk(KERN_ERR DRV_MODULE_NAME
754 ": %s driver bug! interrupt while in poll!\n",
756 FC(fecp
, imask
, FEC_ENET_RXF
| FEC_ENET_RXB
);
761 if ((int_events
& FEC_ENET_TXF
) != 0)
768 /* This interrupt occurs when the PHY detects a link change. */
770 fec_mii_link_interrupt(int irq
, void *dev_id
)
772 struct net_device
*dev
= dev_id
;
773 struct fec_enet_private
*fep
;
774 const struct fec_platform_info
*fpi
;
776 if (unlikely(dev
== NULL
))
779 fep
= netdev_priv(dev
);
786 * Acknowledge the interrupt if possible. If we have not
787 * found the PHY yet we can't process or acknowledge the
788 * interrupt now. Instead we ignore this interrupt for now,
789 * which we can do since it is edge triggered. It will be
790 * acknowledged later by fec_enet_open().
795 fec_mii_ack_int(dev
);
796 fec_mii_link_status_change_check(dev
, 0);
802 /**********************************************************************************/
804 static int fec_enet_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
806 struct fec_enet_private
*fep
= netdev_priv(dev
);
807 fec_t
*fecp
= fep
->fecp
;
812 spin_lock_irqsave(&fep
->tx_lock
, flags
);
815 * Fill in a Tx ring entry
819 if (!fep
->tx_free
|| (CBDR_SC(bdp
) & BD_ENET_TX_READY
)) {
820 netif_stop_queue(dev
);
821 spin_unlock_irqrestore(&fep
->tx_lock
, flags
);
824 * Ooops. All transmit buffers are full. Bail out.
825 * This should not happen, since the tx queue should be stopped.
827 printk(KERN_WARNING DRV_MODULE_NAME
828 ": %s tx queue full!.\n", dev
->name
);
832 curidx
= bdp
- fep
->tx_bd_base
;
834 * Clear all of the status flags.
836 CBDC_SC(bdp
, BD_ENET_TX_STATS
);
841 fep
->tx_skbuff
[curidx
] = skb
;
843 fep
->stats
.tx_bytes
+= skb
->len
;
846 * Push the data cache so the CPM does not get stale memory data.
848 CBDW_BUFADDR(bdp
, dma_map_single(NULL
, skb
->data
,
849 skb
->len
, DMA_TO_DEVICE
));
850 CBDW_DATLEN(bdp
, skb
->len
);
852 dev
->trans_start
= jiffies
;
855 * If this was the last BD in the ring, start at the beginning again.
857 if ((CBDR_SC(bdp
) & BD_ENET_TX_WRAP
) == 0)
860 fep
->cur_tx
= fep
->tx_bd_base
;
863 netif_stop_queue(dev
);
866 * Trigger transmission start
868 CBDS_SC(bdp
, BD_ENET_TX_READY
| BD_ENET_TX_INTR
|
869 BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
870 FW(fecp
, x_des_active
, 0x01000000);
872 spin_unlock_irqrestore(&fep
->tx_lock
, flags
);
877 static void fec_timeout(struct net_device
*dev
)
879 struct fec_enet_private
*fep
= netdev_priv(dev
);
881 fep
->stats
.tx_errors
++;
884 netif_wake_queue(dev
);
886 /* check link status again */
887 fec_mii_link_status_change_check(dev
, 0);
890 static int fec_enet_open(struct net_device
*dev
)
892 struct fec_enet_private
*fep
= netdev_priv(dev
);
893 const struct fec_platform_info
*fpi
= fep
->fpi
;
896 /* Install our interrupt handler. */
897 if (request_irq(fpi
->fec_irq
, fec_enet_interrupt
, 0, "fec", dev
) != 0) {
898 printk(KERN_ERR DRV_MODULE_NAME
899 ": %s Could not allocate FEC IRQ!", dev
->name
);
903 /* Install our phy interrupt handler */
904 if (fpi
->phy_irq
!= -1 &&
905 request_irq(fpi
->phy_irq
, fec_mii_link_interrupt
, 0, "fec-phy",
907 printk(KERN_ERR DRV_MODULE_NAME
908 ": %s Could not allocate PHY IRQ!", dev
->name
);
909 free_irq(fpi
->fec_irq
, dev
);
914 fec_mii_startup(dev
);
915 netif_carrier_off(dev
);
916 fec_mii_link_status_change_check(dev
, 1);
918 spin_lock_irqsave(&fep
->lock
, flags
);
919 fec_restart(dev
, 1, 100); /* XXX this sucks */
920 spin_unlock_irqrestore(&fep
->lock
, flags
);
922 netif_carrier_on(dev
);
923 netif_start_queue(dev
);
928 static int fec_enet_close(struct net_device
*dev
)
930 struct fec_enet_private
*fep
= netdev_priv(dev
);
931 const struct fec_platform_info
*fpi
= fep
->fpi
;
934 netif_stop_queue(dev
);
935 netif_carrier_off(dev
);
938 fec_mii_shutdown(dev
);
940 spin_lock_irqsave(&fep
->lock
, flags
);
942 spin_unlock_irqrestore(&fep
->lock
, flags
);
944 /* release any irqs */
945 if (fpi
->phy_irq
!= -1)
946 free_irq(fpi
->phy_irq
, dev
);
947 free_irq(fpi
->fec_irq
, dev
);
952 static struct net_device_stats
*fec_enet_get_stats(struct net_device
*dev
)
954 struct fec_enet_private
*fep
= netdev_priv(dev
);
958 static int fec_enet_poll(struct net_device
*dev
, int *budget
)
960 return fec_enet_rx_common(dev
, budget
);
963 /*************************************************************************/
965 static void fec_get_drvinfo(struct net_device
*dev
,
966 struct ethtool_drvinfo
*info
)
968 strcpy(info
->driver
, DRV_MODULE_NAME
);
969 strcpy(info
->version
, DRV_MODULE_VERSION
);
972 static int fec_get_regs_len(struct net_device
*dev
)
974 return sizeof(fec_t
);
977 static void fec_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
,
980 struct fec_enet_private
*fep
= netdev_priv(dev
);
983 if (regs
->len
< sizeof(fec_t
))
987 spin_lock_irqsave(&fep
->lock
, flags
);
988 memcpy_fromio(p
, fep
->fecp
, sizeof(fec_t
));
989 spin_unlock_irqrestore(&fep
->lock
, flags
);
992 static int fec_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
994 struct fec_enet_private
*fep
= netdev_priv(dev
);
998 spin_lock_irqsave(&fep
->lock
, flags
);
999 rc
= mii_ethtool_gset(&fep
->mii_if
, cmd
);
1000 spin_unlock_irqrestore(&fep
->lock
, flags
);
1005 static int fec_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1007 struct fec_enet_private
*fep
= netdev_priv(dev
);
1008 unsigned long flags
;
1011 spin_lock_irqsave(&fep
->lock
, flags
);
1012 rc
= mii_ethtool_sset(&fep
->mii_if
, cmd
);
1013 spin_unlock_irqrestore(&fep
->lock
, flags
);
1018 static int fec_nway_reset(struct net_device
*dev
)
1020 struct fec_enet_private
*fep
= netdev_priv(dev
);
1021 return mii_nway_restart(&fep
->mii_if
);
1024 static __u32
fec_get_msglevel(struct net_device
*dev
)
1026 struct fec_enet_private
*fep
= netdev_priv(dev
);
1027 return fep
->msg_enable
;
1030 static void fec_set_msglevel(struct net_device
*dev
, __u32 value
)
1032 struct fec_enet_private
*fep
= netdev_priv(dev
);
1033 fep
->msg_enable
= value
;
1036 static const struct ethtool_ops fec_ethtool_ops
= {
1037 .get_drvinfo
= fec_get_drvinfo
,
1038 .get_regs_len
= fec_get_regs_len
,
1039 .get_settings
= fec_get_settings
,
1040 .set_settings
= fec_set_settings
,
1041 .nway_reset
= fec_nway_reset
,
1042 .get_link
= ethtool_op_get_link
,
1043 .get_msglevel
= fec_get_msglevel
,
1044 .set_msglevel
= fec_set_msglevel
,
1045 .get_tx_csum
= ethtool_op_get_tx_csum
,
1046 .set_tx_csum
= ethtool_op_set_tx_csum
, /* local! */
1047 .get_sg
= ethtool_op_get_sg
,
1048 .set_sg
= ethtool_op_set_sg
,
1049 .get_regs
= fec_get_regs
,
1052 static int fec_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1054 struct fec_enet_private
*fep
= netdev_priv(dev
);
1055 struct mii_ioctl_data
*mii
= (struct mii_ioctl_data
*)&rq
->ifr_data
;
1056 unsigned long flags
;
1059 if (!netif_running(dev
))
1062 spin_lock_irqsave(&fep
->lock
, flags
);
1063 rc
= generic_mii_ioctl(&fep
->mii_if
, mii
, cmd
, NULL
);
1064 spin_unlock_irqrestore(&fep
->lock
, flags
);
1068 int fec_8xx_init_one(const struct fec_platform_info
*fpi
,
1069 struct net_device
**devp
)
1071 immap_t
*immap
= (immap_t
*) IMAP_ADDR
;
1072 static int fec_8xx_version_printed
= 0;
1073 struct net_device
*dev
= NULL
;
1074 struct fec_enet_private
*fep
= NULL
;
1083 switch (fpi
->fec_no
) {
1085 fecp
= &((immap_t
*) IMAP_ADDR
)->im_cpm
.cp_fec
;
1089 fecp
= &((immap_t
*) IMAP_ADDR
)->im_cpm
.cp_fec2
;
1096 if (fec_8xx_version_printed
++ == 0)
1097 printk(KERN_INFO
"%s", version
);
1099 i
= sizeof(*fep
) + (sizeof(struct sk_buff
**) *
1100 (fpi
->rx_ring
+ fpi
->tx_ring
));
1102 dev
= alloc_etherdev(i
);
1107 SET_MODULE_OWNER(dev
);
1109 fep
= netdev_priv(dev
);
1111 /* partial reset of FEC */
1112 fec_whack_reset(fecp
);
1114 /* point rx_skbuff, tx_skbuff */
1115 fep
->rx_skbuff
= (struct sk_buff
**)&fep
[1];
1116 fep
->tx_skbuff
= fep
->rx_skbuff
+ fpi
->rx_ring
;
1122 spin_lock_init(&fep
->lock
);
1123 spin_lock_init(&fep
->tx_lock
);
1126 * Set the Ethernet address.
1128 for (i
= 0; i
< 6; i
++)
1129 dev
->dev_addr
[i
] = fpi
->macaddr
[i
];
1131 fep
->ring_base
= dma_alloc_coherent(NULL
,
1132 (fpi
->tx_ring
+ fpi
->rx_ring
) *
1133 sizeof(cbd_t
), &fep
->ring_mem_addr
,
1135 if (fep
->ring_base
== NULL
) {
1136 printk(KERN_ERR DRV_MODULE_NAME
1137 ": %s dma alloc failed.\n", dev
->name
);
1143 * Set receive and transmit descriptor base.
1145 fep
->rx_bd_base
= fep
->ring_base
;
1146 fep
->tx_bd_base
= fep
->rx_bd_base
+ fpi
->rx_ring
;
1148 /* initialize ring size variables */
1149 fep
->tx_ring
= fpi
->tx_ring
;
1150 fep
->rx_ring
= fpi
->rx_ring
;
1153 if (fpi
->phy_irq
!= -1 &&
1154 (fpi
->phy_irq
>= SIU_IRQ0
&& fpi
->phy_irq
< SIU_LEVEL7
)) {
1156 siel
= in_be32(&immap
->im_siu_conf
.sc_siel
);
1157 if ((fpi
->phy_irq
& 1) == 0)
1158 siel
|= (0x80000000 >> fpi
->phy_irq
);
1160 siel
&= ~(0x80000000 >> (fpi
->phy_irq
& ~1));
1161 out_be32(&immap
->im_siu_conf
.sc_siel
, siel
);
1165 * The FEC Ethernet specific entries in the device structure.
1167 dev
->open
= fec_enet_open
;
1168 dev
->hard_start_xmit
= fec_enet_start_xmit
;
1169 dev
->tx_timeout
= fec_timeout
;
1170 dev
->watchdog_timeo
= TX_TIMEOUT
;
1171 dev
->stop
= fec_enet_close
;
1172 dev
->get_stats
= fec_enet_get_stats
;
1173 dev
->set_multicast_list
= fec_set_multicast_list
;
1174 dev
->set_mac_address
= fec_set_mac_address
;
1175 if (fpi
->use_napi
) {
1176 dev
->poll
= fec_enet_poll
;
1177 dev
->weight
= fpi
->napi_weight
;
1179 dev
->ethtool_ops
= &fec_ethtool_ops
;
1180 dev
->do_ioctl
= fec_ioctl
;
1182 fep
->fec_phy_speed
=
1183 ((((fpi
->sys_clk
+ 4999999) / 2500000) / 2) & 0x3F) << 1;
1185 init_timer(&fep
->phy_timer_list
);
1187 /* partial reset of FEC so that only MII works */
1188 FW(fecp
, mii_speed
, fep
->fec_phy_speed
);
1189 FW(fecp
, ievent
, 0xffc0);
1190 FW(fecp
, ivec
, (fpi
->fec_irq
/ 2) << 29);
1192 FW(fecp
, r_cntrl
, FEC_RCNTRL_MII_MODE
); /* MII enable */
1193 FW(fecp
, ecntrl
, FEC_ECNTRL_PINMUX
| FEC_ECNTRL_ETHER_EN
);
1195 netif_carrier_off(dev
);
1197 err
= register_netdev(dev
);
1202 if (fpi
->use_mdio
) {
1203 fep
->mii_if
.dev
= dev
;
1204 fep
->mii_if
.mdio_read
= fec_mii_read
;
1205 fep
->mii_if
.mdio_write
= fec_mii_write
;
1206 fep
->mii_if
.phy_id_mask
= 0x1f;
1207 fep
->mii_if
.reg_num_mask
= 0x1f;
1208 fep
->mii_if
.phy_id
= fec_mii_phy_id_detect(dev
);
1218 fec_whack_reset(fecp
);
1221 unregister_netdev(dev
);
1225 dma_free_coherent(NULL
,
1228 sizeof(cbd_t
), fep
->ring_base
,
1229 fep
->ring_mem_addr
);
1236 int fec_8xx_cleanup_one(struct net_device
*dev
)
1238 struct fec_enet_private
*fep
= netdev_priv(dev
);
1239 fec_t
*fecp
= fep
->fecp
;
1240 const struct fec_platform_info
*fpi
= fep
->fpi
;
1242 fec_whack_reset(fecp
);
1244 unregister_netdev(dev
);
1246 dma_free_coherent(NULL
, (fpi
->tx_ring
+ fpi
->rx_ring
) * sizeof(cbd_t
),
1247 fep
->ring_base
, fep
->ring_mem_addr
);
1254 /**************************************************************************************/
1255 /**************************************************************************************/
1256 /**************************************************************************************/
1258 static int __init
fec_8xx_init(void)
1260 return fec_8xx_platform_init();
1263 static void __exit
fec_8xx_cleanup(void)
1265 fec_8xx_platform_cleanup();
1268 /**************************************************************************************/
1269 /**************************************************************************************/
1270 /**************************************************************************************/
1272 module_init(fec_8xx_init
);
1273 module_exit(fec_8xx_cleanup
);