37 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
39 #include <linux/capability.h>
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/string.h>
45 #include <linux/errno.h>
48 #include <linux/bitops.h>
49 #include <linux/slab.h>
52 #include <linux/netdevice.h>
54 #include <linux/ethtool.h>
55 #include <linux/mii.h>
66 #include <asm/processor.h>
74 #ifdef AU1000_ETH_DEBUG
75 static int au1000_debug = 5;
77 static int au1000_debug = 3;
80 #define AU1000_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
84 #define DRV_NAME "au1000_eth"
85 #define DRV_VERSION "1.7"
87 #define DRV_DESC "Au1xxx on-chip Ethernet driver"
148 static void au1000_enable_mac(
struct net_device *
dev,
int force_reset)
165 spin_unlock_irqrestore(&aup->
lock, flags);
174 u32 *
const mii_control_reg = &aup->
mac->mii_control;
175 u32 *
const mii_data_reg = &aup->
mac->mii_data;
181 if (--timedout == 0) {
182 netdev_err(dev,
"read_MII busy timeout!!\n");
190 writel(mii_control, mii_control_reg);
193 while (
readl(mii_control_reg) & MAC_MII_BUSY) {
195 if (--timedout == 0) {
196 netdev_err(dev,
"mdio_read busy timeout!!\n");
200 return readl(mii_data_reg);
203 static void au1000_mdio_write(
struct net_device *dev,
int phy_addr,
207 u32 *
const mii_control_reg = &aup->
mac->mii_control;
208 u32 *
const mii_data_reg = &aup->
mac->mii_data;
212 while (
readl(mii_control_reg) & MAC_MII_BUSY) {
214 if (--timedout == 0) {
215 netdev_err(dev,
"mdio_write busy timeout!!\n");
223 writel(value, mii_data_reg);
224 writel(mii_control, mii_control_reg);
227 static int au1000_mdiobus_read(
struct mii_bus *
bus,
int phy_addr,
int regnum)
237 au1000_enable_mac(dev, 0);
239 return au1000_mdio_read(dev, phy_addr, regnum);
242 static int au1000_mdiobus_write(
struct mii_bus *
bus,
int phy_addr,
int regnum,
250 au1000_enable_mac(dev, 0);
252 au1000_mdio_write(dev, phy_addr, regnum, value);
256 static int au1000_mdiobus_reset(
struct mii_bus *
bus)
263 au1000_enable_mac(dev, 0);
268 static void au1000_hard_stop(
struct net_device *dev)
281 static void au1000_enable_rx_tx(
struct net_device *dev)
302 int status_change = 0;
311 switch (phydev->
speed) {
316 netdev_warn(dev,
"Speed (%d) is not 10/100 ???\n",
330 au1000_hard_stop(dev);
343 au1000_enable_rx_tx(dev);
362 spin_unlock_irqrestore(&aup->
lock, flags);
366 netdev_info(dev,
"link up (%d/%s)\n",
370 netdev_info(dev,
"link down\n");
374 static int au1000_mii_probe(
struct net_device *dev)
386 netdev_info(dev,
"using PHY-less setup\n");
394 if (aup->
mii_bus->phy_map[phy_addr]) {
395 phydev = aup->
mii_bus->phy_map[phy_addr];
403 if (!phydev && (aup->
mac_id == 1)) {
406 "let's see if it's attached to MAC0...\n");
411 for (phy_addr = 0; phy_addr <
PHY_MAX_ADDR; phy_addr++) {
413 aup->
mii_bus->phy_map[phy_addr];
433 netdev_err(dev,
"no PHY found\n");
440 phydev =
phy_connect(dev, dev_name(&phydev->
dev), &au1000_adjust_link,
443 if (IS_ERR(phydev)) {
444 netdev_err(dev,
"Could not attach to PHY\n");
445 return PTR_ERR(phydev);
465 netdev_info(dev,
"attached PHY driver [%s] "
466 "(mii_bus:phy_addr=%s, irq=%d)\n",
467 phydev->
drv->name, dev_name(&phydev->
dev), phydev->
irq);
493 pDBfree->
pnext = pDB;
497 static void au1000_reset_mac_unlocked(
struct net_device *dev)
502 au1000_hard_stop(dev);
523 static void au1000_reset_mac(
struct net_device *dev)
533 au1000_reset_mac_unlocked(dev);
535 spin_unlock_irqrestore(&aup->
lock, flags);
550 (tx_base + 0x100 +
sizeof(
struct rx_dma) *
i);
554 (tx_base +
sizeof(
struct tx_dma) *
i);
597 static void au1000_set_msglevel(
struct net_device *dev,
u32 value)
609 static const struct ethtool_ops au1000_ethtool_ops = {
610 .get_settings = au1000_get_settings,
611 .set_settings = au1000_set_settings,
612 .get_drvinfo = au1000_get_drvinfo,
614 .get_msglevel = au1000_get_msglevel,
615 .set_msglevel = au1000_set_msglevel,
628 static int au1000_init(
struct net_device *dev)
638 au1000_enable_mac(dev, 1);
648 &aup->
mac->mac_addr_high);
651 &aup->
mac->mac_addr_low);
660 #ifndef CONFIG_CPU_LITTLE_ENDIAN
676 spin_unlock_irqrestore(&aup->
lock, flags);
722 au1000_update_rx_stats(dev, status);
723 if (!(status & RX_ERROR)) {
728 skb = netdev_alloc_skb(dev, frmlen + 2);
730 netdev_err(dev,
"Memory squeeze, dropping packet.\n");
731 dev->
stats.rx_dropped++;
735 skb_copy_to_linear_data(skb,
736 (
unsigned char *)pDB->
vaddr, frmlen);
741 if (au1000_debug > 4) {
743 if (status & RX_MISSED_FRAME)
775 static void au1000_update_tx_stats(
struct net_device *dev,
u32 status)
803 static void au1000_tx_ack(
struct net_device *dev)
811 au1000_update_tx_stats(dev, ptxd->
status);
821 netif_wake_queue(dev);
840 static int au1000_open(
struct net_device *dev)
845 netif_dbg(aup, drv, dev,
"open: dev=%p\n", dev);
850 netdev_err(dev,
"unable to get IRQ %d\n", dev->
irq);
854 retval = au1000_init(dev);
856 netdev_err(dev,
"error in au1000_init\n");
867 netif_start_queue(dev);
869 netif_dbg(aup, drv, dev,
"open: Initialization done.\n");
874 static int au1000_close(
struct net_device *dev)
879 netif_dbg(aup, drv, dev,
"close: dev=%p\n", dev);
886 au1000_reset_mac_unlocked(dev);
889 netif_stop_queue(dev);
893 spin_unlock_irqrestore(&aup->
lock, flags);
910 netif_dbg(aup, tx_queued, dev,
"tx: aup %x len=%d, data=%p, head %d\n",
911 (
unsigned)aup, skb->
len,
912 skb->
data, aup->tx_head);
918 netif_stop_queue(dev);
922 au1000_update_tx_stats(dev, ptxd->
status);
928 netif_wake_queue(dev);
932 skb_copy_from_linear_data(skb, (
void *)pDB->
vaddr, skb->
len);
935 ((
char *)pDB->
vaddr)[
i] = 0;
955 static void au1000_tx_timeout(
struct net_device *dev)
957 netdev_err(dev,
"au1000_tx_timeout: dev=%p\n", dev);
958 au1000_reset_mac(dev);
961 netif_wake_queue(dev);
964 static void au1000_multicast_list(
struct net_device *dev)
977 netdev_info(dev,
"Pass all multicast\n");
982 mc_filter[1] = mc_filter[0] = 0;
986 writel(mc_filter[1], &aup->
mac->multi_hash_high);
987 writel(mc_filter[0], &aup->
mac->multi_hash_low);
998 if (!netif_running(dev))
1008 .ndo_open = au1000_open,
1009 .ndo_stop = au1000_close,
1010 .ndo_start_xmit = au1000_tx,
1011 .ndo_set_rx_mode = au1000_multicast_list,
1012 .ndo_do_ioctl = au1000_ioctl,
1013 .ndo_tx_timeout = au1000_tx_timeout,
1021 static unsigned version_printed;
1025 struct db_dest *pDB, *pDBfree;
1031 dev_err(&pdev->
dev,
"failed to retrieve base register\n");
1038 dev_err(&pdev->
dev,
"failed to retrieve MAC Enable register\n");
1045 dev_err(&pdev->
dev,
"failed to retrieve IRQ\n");
1052 dev_err(&pdev->
dev,
"failed to retrieve MACDMA registers\n");
1059 dev_err(&pdev->
dev,
"failed to request memory region for base registers\n");
1066 dev_err(&pdev->
dev,
"failed to request memory region for MAC enable register\n");
1073 dev_err(&pdev->
dev,
"failed to request MACDMA memory region\n");
1085 platform_set_drvdata(pdev, dev);
1086 aup = netdev_priv(dev);
1099 dev_err(&pdev->
dev,
"failed to allocate data buffers\n");
1108 dev_err(&pdev->
dev,
"failed to ioremap MAC registers\n");
1115 resource_size(macen));
1117 dev_err(&pdev->
dev,
"failed to ioremap MAC enable register\n");
1125 dev_err(&pdev->
dev,
"failed to ioremap MACDMA registers\n");
1130 au1000_setup_hw_rings(aup, aup->
macdma);
1135 pd = pdev->
dev.platform_data;
1138 " PHY search on MAC0\n");
1141 if (is_valid_ether_addr(pd->
mac)) {
1145 eth_hw_addr_random(dev);
1157 dev_err(&pdev->
dev,
"MAC0-associated PHY attached 2nd MACs MII bus not supported yet\n");
1159 goto err_mdiobus_alloc;
1162 aup->
mii_bus = mdiobus_alloc();
1164 dev_err(&pdev->
dev,
"failed to allocate mdiobus structure\n");
1166 goto err_mdiobus_alloc;
1170 aup->
mii_bus->read = au1000_mdiobus_read;
1171 aup->
mii_bus->write = au1000_mdiobus_write;
1172 aup->
mii_bus->reset = au1000_mdiobus_reset;
1173 aup->
mii_bus->name =
"au1000_eth_mii";
1191 dev_err(&pdev->
dev,
"failed to register MDIO bus\n");
1192 goto err_mdiobus_reg;
1195 err = au1000_mii_probe(dev);
1203 pDB->
pnext = pDBfree;
1213 pDB = au1000_GetFreeDB(aup);
1223 pDB = au1000_GetFreeDB(aup);
1242 au1000_reset_mac(dev);
1246 netdev_err(dev,
"Cannot register net device, aborting.\n");
1250 netdev_info(dev,
"Au1xx0 Ethernet found at 0x%lx, irq %d\n",
1251 (
unsigned long)base->
start, irq);
1252 if (version_printed++ == 0)
1265 au1000_reset_mac(dev);
1300 struct net_device *dev = platform_get_drvdata(pdev);
1305 platform_set_drvdata(pdev,
NULL);
1342 .probe = au1000_probe,
1345 .name =
"au1000-eth",