18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/types.h>
21 #include <linux/string.h>
22 #include <linux/ptrace.h>
23 #include <linux/errno.h>
25 #include <linux/slab.h>
29 #include <linux/netdevice.h>
33 #include <linux/mii.h>
34 #include <linux/ethtool.h>
35 #include <linux/bitops.h>
46 #include <asm/pgtable.h>
48 #include <asm/uaccess.h>
59 static int fs_enet_debug = -1;
62 "Freescale bitmapped debugging message enable value");
64 #ifdef CONFIG_NET_POLL_CONTROLLER
72 (*fep->
ops->set_multicast_list)(dev);
77 int off = ((
unsigned long)skb->
data) & (align - 1);
80 skb_reserve(skb, align - off);
102 (*fep->
ops->napi_clear_rx_event)(dev);
119 fep->
stats.rx_errors++;
122 fep->
stats.rx_length_errors++;
125 fep->
stats.rx_frame_errors++;
128 fep->
stats.rx_crc_errors++;
131 fep->
stats.rx_crc_errors++;
151 fep->
stats.rx_packets++;
153 fep->
stats.rx_bytes += pkt_len + 4;
155 if (pkt_len <= fpi->rx_copybreak) {
157 skbn = netdev_alloc_skb(dev, pkt_len + 2);
159 skb_reserve(skbn, 2);
160 skb_copy_from_linear_data(skb,
161 skbn->
data, pkt_len);
181 "Memory squeeze, dropping packet.\n");
182 fep->
stats.rx_dropped++;
202 (*fep->
ops->rx_bd_done)(dev);
204 if (received >= budget)
210 if (received < budget) {
213 (*fep->
ops->napi_enable_rx)(dev);
219 static int fs_enet_rx_non_napi(
struct net_device *dev)
234 while (((sc =
CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
242 if ((sc & BD_ENET_RX_LAST) == 0)
250 fep->
stats.rx_errors++;
253 fep->
stats.rx_length_errors++;
256 fep->
stats.rx_frame_errors++;
258 if (sc & BD_ENET_RX_CR)
259 fep->
stats.rx_crc_errors++;
261 if (sc & BD_ENET_RX_OV)
262 fep->
stats.rx_crc_errors++;
283 fep->
stats.rx_packets++;
285 fep->
stats.rx_bytes += pkt_len + 4;
287 if (pkt_len <= fpi->rx_copybreak) {
289 skbn = netdev_alloc_skb(dev, pkt_len + 2);
291 skb_reserve(skbn, 2);
292 skb_copy_from_linear_data(skb,
293 skbn->
data, pkt_len);
313 "Memory squeeze, dropping packet.\n");
314 fep->
stats.rx_dropped++;
329 if ((sc & BD_ENET_RX_WRAP) == 0)
334 (*fep->
ops->rx_bd_done)(dev);
342 static void fs_enet_tx(
struct net_device *dev)
353 do_wake = do_restart = 0;
369 fep->
stats.tx_heartbeat_errors++;
371 fep->
stats.tx_window_errors++;
373 fep->
stats.tx_aborted_errors++;
375 fep->
stats.tx_fifo_errors++;
377 fep->
stats.tx_carrier_errors++;
379 if (sc & (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
380 fep->
stats.tx_errors++;
384 fep->
stats.tx_packets++;
386 if (sc & BD_ENET_TX_READY) {
388 "HEY! Enet xmit interrupt and TX_READY.\n");
396 fep->
stats.collisions++;
427 (*fep->
ops->tx_restart)(dev);
432 netif_wake_queue(dev);
440 fs_enet_interrupt(
int irq,
void *
dev_id)
450 fep = netdev_priv(dev);
454 while ((int_events = (*fep->
ops->get_int_events)(dev)) != 0) {
457 int_clr_events = int_events;
461 (*fep->
ops->clear_int_events)(dev, int_clr_events);
463 if (int_events & fep->
ev_err)
464 (*fep->
ops->ev_error)(dev, int_events);
466 if (int_events & fep->
ev_rx) {
468 fs_enet_rx_non_napi(dev);
470 napi_ok = napi_schedule_prep(&fep->
napi);
472 (*fep->
ops->napi_disable_rx)(dev);
482 if (int_events & fep->
ev_tx)
510 "Memory squeeze, unable to allocate skb\n");
520 CBDW_SC(bdp, BD_ENET_RX_EMPTY |
526 for (; i < fep->
rx_ring; i++, bdp++) {
584 #ifdef CONFIG_FS_ENET_MPC5121_FEC
595 new_skb = netdev_alloc_skb(dev, skb->
len + 4);
599 "Memory squeeze, dropping tx packet.\n");
605 skb_align(new_skb, 4);
608 skb_copy_from_linear_data(skb, new_skb->
data, skb->
len);
626 #ifdef CONFIG_FS_ENET_MPC5121_FEC
627 if (((
unsigned long)skb->
data) & 0x3) {
628 skb = tx_skb_align_workaround(dev, skb);
647 netif_stop_queue(dev);
648 spin_unlock_irqrestore(&fep->
tx_lock, flags);
681 if ((
CBDR_SC(bdp) & BD_ENET_TX_WRAP) == 0)
687 netif_stop_queue(dev);
700 skb_tx_timestamp(skb);
702 (*fep->
ops->tx_kickstart)(dev);
704 spin_unlock_irqrestore(&fep->
tx_lock, flags);
709 static void fs_timeout(
struct net_device *dev)
715 fep->
stats.tx_errors++;
721 (*fep->
ops->stop)(dev);
722 (*fep->
ops->restart)(dev);
728 spin_unlock_irqrestore(&fep->
lock, flags);
731 netif_wake_queue(dev);
737 static void generic_adjust_link(
struct net_device *dev)
761 fep->
ops->restart(dev);
774 static void fs_adjust_link(
struct net_device *dev)
781 if(fep->
ops->adjust_link)
782 fep->
ops->adjust_link(dev);
784 generic_adjust_link(dev);
786 spin_unlock_irqrestore(&fep->
lock, flags);
789 static int fs_init_phy(
struct net_device *dev)
799 iface = fep->
fpi->use_rmii ?
809 dev_err(&dev->
dev,
"Could not attach to PHY\n");
818 static int fs_enet_open(
struct net_device *dev)
828 if (fep->
fpi->use_napi)
829 napi_enable(&fep->
napi);
835 dev_err(fep->
dev,
"Could not allocate FS_ENET IRQ!");
836 if (fep->
fpi->use_napi)
837 napi_disable(&fep->
napi);
841 err = fs_init_phy(dev);
844 if (fep->
fpi->use_napi)
845 napi_disable(&fep->
napi);
850 netif_start_queue(dev);
855 static int fs_enet_close(
struct net_device *dev)
860 netif_stop_queue(dev);
862 if (fep->
fpi->use_napi)
863 napi_disable(&fep->
napi);
868 (*fep->
ops->stop)(dev);
870 spin_unlock_irqrestore(&fep->
lock, flags);
888 static void fs_get_drvinfo(
struct net_device *dev,
895 static int fs_get_regs_len(
struct net_device *dev)
899 return (*fep->
ops->get_regs_len)(
dev);
912 r = (*fep->
ops->get_regs)(dev, p, &len);
913 spin_unlock_irqrestore(&fep->
lock, flags);
939 static int fs_nway_reset(
struct net_device *dev)
957 .get_drvinfo = fs_get_drvinfo,
958 .get_regs_len = fs_get_regs_len,
959 .get_settings = fs_get_settings,
960 .set_settings = fs_set_settings,
961 .nway_reset = fs_nway_reset,
963 .get_msglevel = fs_get_msglevel,
964 .set_msglevel = fs_set_msglevel,
965 .get_regs = fs_get_regs,
973 if (!netif_running(dev))
984 #ifdef CONFIG_FS_ENET_HAS_FEC
985 #define IS_FEC(match) ((match)->data == &fs_fec_ops)
987 #define IS_FEC(match) 0
991 .ndo_open = fs_enet_open,
992 .ndo_stop = fs_enet_close,
993 .ndo_get_stats = fs_enet_get_stats,
994 .ndo_start_xmit = fs_enet_start_xmit,
995 .ndo_tx_timeout = fs_timeout,
996 .ndo_set_rx_mode = fs_set_multicast_list,
997 .ndo_do_ioctl = fs_ioctl,
1001 #ifdef CONFIG_NET_POLL_CONTROLLER
1002 .ndo_poll_controller = fs_enet_netpoll,
1015 const char *phy_connection_type;
1028 if (!data || len != 4)
1046 "phy-connection-type",
NULL);
1047 if (phy_connection_type && !
strcmp(
"rmii", phy_connection_type))
1051 privsize =
sizeof(*fep) +
1055 ndev = alloc_etherdev(privsize);
1064 fep = netdev_priv(ndev);
1070 ret = fep->
ops->setup_data(ndev);
1084 ret = fep->
ops->allocate_bd(ndev);
1086 goto out_cleanup_data;
1115 fep->
ops->free_bd(ndev);
1117 fep->
ops->cleanup_data(ndev);
1135 fep->
ops->free_bd(ndev);
1136 fep->
ops->cleanup_data(ndev);
1138 of_node_put(fep->
fpi->phy_node);
1144 #ifdef CONFIG_FS_ENET_HAS_SCC
1146 .compatible =
"fsl,cpm1-scc-enet",
1150 .compatible =
"fsl,cpm2-scc-enet",
1154 #ifdef CONFIG_FS_ENET_HAS_FCC
1156 .compatible =
"fsl,cpm2-fcc-enet",
1160 #ifdef CONFIG_FS_ENET_HAS_FEC
1161 #ifdef CONFIG_FS_ENET_MPC5121_FEC
1163 .compatible =
"fsl,mpc5121-fec",
1167 .compatible =
"fsl,mpc5125-fec",
1172 .compatible =
"fsl,pq1-fec-enet",
1185 .of_match_table = fs_enet_match,
1187 .probe = fs_enet_probe,
1188 .remove = fs_enet_remove,
1191 #ifdef CONFIG_NET_POLL_CONTROLLER
1192 static void fs_enet_netpoll(
struct net_device *dev)
1195 fs_enet_interrupt(dev->
irq, dev);