18 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/types.h>
23 #include <linux/slab.h>
24 #include <linux/errno.h>
34 #include <linux/netdevice.h>
36 #include <linux/ethtool.h>
40 #include <asm/delay.h>
48 #define DRIVER_NAME "mpc52xx-fec"
72 static irqreturn_t mpc52xx_fec_interrupt(
int,
void *);
73 static irqreturn_t mpc52xx_fec_rx_interrupt(
int,
void *);
74 static irqreturn_t mpc52xx_fec_tx_interrupt(
int,
void *);
79 static u8 mpc52xx_fec_mac_addr[6];
83 #define MPC52xx_MESSAGES_DEFAULT ( NETIF_MSG_DRV | NETIF_MSG_PROBE | \
84 NETIF_MSG_LINK | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP)
85 static int debug = -1;
97 mpc52xx_fec_reset(dev);
98 dev->
stats.tx_errors++;
99 spin_unlock_irqrestore(&priv->
lock, flags);
101 netif_wake_queue(dev);
122 static int mpc52xx_fec_set_mac_address(
struct net_device *dev,
void *
addr)
128 mpc52xx_fec_set_paddr(dev, sock->
sa_data);
134 while (!bcom_queue_empty(s)) {
138 skb = bcom_retrieve_buffer(s,
NULL, (
struct bcom_bd **)&bd);
155 bcom_submit_next_buffer(priv->
rx_dmatsk, rskb);
162 while (!bcom_queue_full(rxtsk)) {
169 mpc52xx_fec_rx_submit(dev, skb);
175 static void mpc52xx_fec_adjust_link(
struct net_device *dev)
214 }
else if (priv->
link) {
225 static int mpc52xx_fec_open(
struct net_device *dev)
232 mpc52xx_fec_adjust_link, 0, 0);
234 dev_err(&dev->
dev,
"of_phy_connect failed\n");
242 dev_err(&dev->
dev,
"ctrl interrupt request failed\n");
247 dev_err(&dev->
dev,
"rx interrupt request failed\n");
252 dev_err(&dev->
dev,
"tx interrupt request failed\n");
259 err = mpc52xx_fec_alloc_rx_buffers(dev, priv->
rx_dmatsk);
261 dev_err(&dev->
dev,
"mpc52xx_fec_alloc_rx_buffers failed\n");
268 mpc52xx_fec_start(dev);
270 netif_start_queue(dev);
290 static int mpc52xx_fec_close(
struct net_device *dev)
294 netif_stop_queue(dev);
296 mpc52xx_fec_stop(dev);
298 mpc52xx_fec_free_rx_buffers(dev, priv->
rx_dmatsk);
327 dev_err(&dev->
dev,
"transmit queue overrun\n");
334 bcom_prepare_next_buffer(priv->
tx_dmatsk);
340 skb_tx_timestamp(skb);
341 bcom_submit_next_buffer(priv->
tx_dmatsk, skb);
342 spin_unlock_irqrestore(&priv->
lock, flags);
345 netif_stop_queue(dev);
351 #ifdef CONFIG_NET_POLL_CONTROLLER
352 static void mpc52xx_fec_poll_controller(
struct net_device *dev)
357 mpc52xx_fec_tx_interrupt(priv->
t_irq, dev);
360 mpc52xx_fec_rx_interrupt(priv->
r_irq, dev);
373 spin_lock(&priv->
lock);
374 while (bcom_buffer_done(priv->
tx_dmatsk)) {
384 spin_unlock(&priv->
lock);
386 netif_wake_queue(dev);
391 static irqreturn_t mpc52xx_fec_rx_interrupt(
int irq,
void *dev_id)
401 spin_lock(&priv->
lock);
403 while (bcom_buffer_done(priv->
rx_dmatsk)) {
405 rskb = bcom_retrieve_buffer(priv->
rx_dmatsk, &status,
412 mpc52xx_fec_rx_submit(dev, rskb);
413 dev->
stats.rx_dropped++;
422 dev_notice(&dev->
dev,
"Low memory - dropped packet.\n");
423 mpc52xx_fec_rx_submit(dev, rskb);
424 dev->
stats.rx_dropped++;
429 mpc52xx_fec_rx_submit(dev, skb);
433 spin_unlock(&priv->
lock);
443 spin_lock(&priv->
lock);
446 spin_unlock(&priv->
lock);
451 static irqreturn_t mpc52xx_fec_interrupt(
int irq,
void *dev_id)
474 spin_lock(&priv->
lock);
475 mpc52xx_fec_reset(dev);
476 spin_unlock(&priv->
lock);
541 static void mpc52xx_fec_reset_stats(
struct net_device *dev)
558 static void mpc52xx_fec_set_multicast_list(
struct net_device *dev)
579 u32 gaddr1 = 0x00000000;
580 u32 gaddr2 = 0x00000000;
585 gaddr1 |= 1 << (crc-32);
601 static void mpc52xx_fec_hw_init(
struct net_device *dev)
614 if (i == FEC_RESET_DELAY)
652 static void mpc52xx_fec_start(
struct net_device *dev)
669 mpc52xx_fec_set_paddr(dev, dev->
dev_addr);
671 mpc52xx_fec_set_multicast_list(dev);
706 static void mpc52xx_fec_stop(
struct net_device *dev)
729 dev_err(&dev->
dev,
" tx: index: %i, outdex: %i\n",
732 dev_err(&dev->
dev,
" rx: index: %i, outdex: %i\n",
746 static void mpc52xx_fec_reset(
struct net_device *dev)
751 mpc52xx_fec_stop(dev);
756 mpc52xx_fec_free_rx_buffers(dev, priv->
rx_dmatsk);
758 mpc52xx_fec_hw_init(dev);
763 mpc52xx_fec_alloc_rx_buffers(dev, priv->
rx_dmatsk);
768 mpc52xx_fec_start(dev);
770 netif_wake_queue(dev);
808 static const struct ethtool_ops mpc52xx_fec_ethtool_ops = {
809 .get_settings = mpc52xx_fec_get_settings,
810 .set_settings = mpc52xx_fec_set_settings,
812 .get_msglevel = mpc52xx_fec_get_msglevel,
813 .set_msglevel = mpc52xx_fec_set_msglevel,
829 .ndo_open = mpc52xx_fec_open,
830 .ndo_stop = mpc52xx_fec_close,
831 .ndo_start_xmit = mpc52xx_fec_start_xmit,
832 .ndo_set_rx_mode = mpc52xx_fec_set_multicast_list,
833 .ndo_set_mac_address = mpc52xx_fec_set_mac_address,
835 .ndo_do_ioctl = mpc52xx_fec_ioctl,
837 .ndo_tx_timeout = mpc52xx_fec_tx_timeout,
838 .ndo_get_stats = mpc52xx_fec_get_stats,
839 #ifdef CONFIG_NET_POLL_CONTROLLER
840 .ndo_poll_controller = mpc52xx_fec_poll_controller,
865 priv = netdev_priv(ndev);
872 "Error while parsing device node resource\n" );
877 " - invalid resource size (%lx < %x), check mpc52xx_devices.c\n",
878 (
unsigned long)resource_size(&
mem),
917 goto err_rx_tx_dmatsk;
931 if (!is_zero_ether_addr(mpc52xx_fec_mac_addr))
934 mpc52xx_fec_get_paddr(ndev, ndev->
dev_addr);
949 if (prop && (prop_size >=
sizeof(
u32) * 2)) {
950 priv->
speed = prop[0];
964 mpc52xx_fec_hw_init(ndev);
965 mpc52xx_fec_reset_stats(ndev);
1000 priv = netdev_priv(ndev);
1028 if (netif_running(dev))
1029 mpc52xx_fec_close(dev);
1038 mpc52xx_fec_hw_init(dev);
1039 mpc52xx_fec_reset_stats(dev);
1041 if (netif_running(dev))
1042 mpc52xx_fec_open(dev);
1049 { .compatible =
"fsl,mpc5200b-fec", },
1050 { .compatible =
"fsl,mpc5200-fec", },
1051 { .compatible =
"mpc5200-fec", },
1061 .of_match_table = mpc52xx_fec_match,
1063 .probe = mpc52xx_fec_probe,
1064 .remove = mpc52xx_fec_remove,
1066 .suspend = mpc52xx_fec_of_suspend,
1067 .resume = mpc52xx_fec_of_resume,
1077 mpc52xx_fec_init(
void)
1079 #ifdef CONFIG_FEC_MPC52xx_MDIO
1083 printk(
KERN_ERR DRIVER_NAME
": failed to register mdio driver\n");
1091 mpc52xx_fec_exit(
void)
1094 #ifdef CONFIG_FEC_MPC52xx_MDIO