X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/43ba67e0d51fc116099a5556191bf09669cd8601..49b34728f956238c5fdbec568be0247fb8be95c6:/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c diff --git a/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c b/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c index 7f53d64d4..fafb5a52f 100644 --- a/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c +++ b/target/linux/ifxmips/files/drivers/net/ifxmips_mii0.c @@ -14,7 +14,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * Copyright (C) 2005 Wu Qi Ming - * Copyright (C) 2008 John Crispin + * Copyright (C) 2008 John Crispin */ #include @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,18 +32,21 @@ #include #include #include -#include #include -#include +#include +#include #include -#include #include #include -#define DRVNAME "ifxmips_mii0" +struct ifxmips_mii_priv { + struct net_device_stats stats; + struct dma_device_info *dma_device; + struct sk_buff *skb; +}; static struct net_device *ifxmips_mii0_dev; -static unsigned char u_boot_ethaddr[MAX_ADDR_LEN]; +static unsigned char mac_addr[MAX_ADDR_LEN]; void ifxmips_write_mdio(u32 phy_addr, u32 phy_reg, u16 phy_data) @@ -56,6 +59,7 @@ ifxmips_write_mdio(u32 phy_addr, u32 phy_reg, u16 phy_data) while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST); ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC); } +EXPORT_SYMBOL(ifxmips_write_mdio); unsigned short ifxmips_read_mdio(u32 phy_addr, u32 phy_reg) @@ -64,11 +68,13 @@ ifxmips_read_mdio(u32 phy_addr, u32 phy_reg) ((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) | ((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET); + while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST); ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC); while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST){}; val = ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_VAL_MASK; return val; } +EXPORT_SYMBOL(ifxmips_read_mdio); int ifxmips_ifxmips_mii_open(struct net_device *dev) @@ -77,9 +83,9 @@ ifxmips_ifxmips_mii_open(struct net_device *dev) struct dma_device_info* dma_dev = priv->dma_device; int i; - for(i = 0; i < dma_dev->max_rx_chan_num; i++) + for (i = 0; i < dma_dev->max_rx_chan_num; i++) { - if((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON) + if ((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON) (dma_dev->rx_chan[i])->open(dma_dev->rx_chan[i]); } netif_start_queue(dev); @@ -92,7 +98,7 @@ ifxmips_mii_release(struct net_device *dev){ struct dma_device_info* dma_dev = priv->dma_device; int i; - for(i = 0; i < dma_dev->max_rx_chan_num; i++) + for (i = 0; i < dma_dev->max_rx_chan_num; i++) dma_dev->rx_chan[i]->close(dma_dev->rx_chan[i]); netif_stop_queue(dev); return 0; @@ -108,23 +114,23 @@ ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev) len = dma_device_read(dma_dev, &buf, (void**)&skb); - if(len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) + if (len >= ETHERNET_PACKET_DMA_BUFFER_SIZE) { - printk(KERN_INFO DRVNAME ": packet too large %d\n",len); + printk(KERN_INFO "ifxmips_mii0: packet too large %d\n",len); goto ifxmips_mii_hw_receive_err_exit; } /* remove CRC */ len -= 4; - if(skb == NULL) + if (skb == NULL) { - printk(KERN_INFO DRVNAME ": cannot restore pointer\n"); + printk(KERN_INFO "ifxmips_mii0: cannot restore pointer\n"); goto ifxmips_mii_hw_receive_err_exit; } - if(len > (skb->end - skb->tail)) + if (len > (skb->end - skb->tail)) { - printk(KERN_INFO DRVNAME ": BUG, len:%d end:%p tail:%p\n", + printk(KERN_INFO "ifxmips_mii0: BUG, len:%d end:%p tail:%p\n", (len+4), skb->end, skb->tail); goto ifxmips_mii_hw_receive_err_exit; } @@ -139,9 +145,9 @@ ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev) return 0; ifxmips_mii_hw_receive_err_exit: - if(len == 0) + if (len == 0) { - if(skb) + if (skb) dev_kfree_skb_any(skb); priv->stats.rx_errors++; priv->stats.rx_dropped++; @@ -157,9 +163,7 @@ ifxmips_mii_hw_tx(char *buf, int len, struct net_device *dev) int ret = 0; struct ifxmips_mii_priv *priv = dev->priv; struct dma_device_info* dma_dev = priv->dma_device; - ret = dma_device_write(dma_dev, buf, len, priv->skb); - return ret; } @@ -181,7 +185,7 @@ ifxmips_mii_tx(struct sk_buff *skb, struct net_device *dev) wmb(); - if(ifxmips_mii_hw_tx(data, len, dev) != len) + if (ifxmips_mii_hw_tx(data, len, dev) != len) { dev_kfree_skb_any(skb); priv->stats.tx_errors++; @@ -201,7 +205,7 @@ ifxmips_mii_tx_timeout(struct net_device *dev) struct ifxmips_mii_priv* priv = (struct ifxmips_mii_priv*)dev->priv; priv->stats.tx_errors++; - for(i = 0; i < priv->dma_device->max_tx_chan_num; i++) + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++) priv->dma_device->tx_chan[i]->disable_irq(priv->dma_device->tx_chan[i]); netif_wake_queue(dev); return; @@ -219,7 +223,7 @@ dma_intr_handler(struct dma_device_info* dma_dev, int status) break; case TX_BUF_FULL_INT: - printk(KERN_INFO DRVNAME ": tx buffer full\n"); + printk(KERN_INFO "ifxmips_mii0: tx buffer full\n"); netif_stop_queue(ifxmips_mii0_dev); for (i = 0; i < dma_dev->max_tx_chan_num; i++) { @@ -229,7 +233,7 @@ dma_intr_handler(struct dma_device_info* dma_dev, int status) break; case TRANSMIT_CPT_INT: - for(i = 0; i < dma_dev->max_tx_chan_num; i++) + for (i = 0; i < dma_dev->max_tx_chan_num; i++) dma_dev->tx_chan[i]->disable_irq(dma_dev->tx_chan[i]); netif_wake_queue(ifxmips_mii0_dev); @@ -246,7 +250,7 @@ ifxmips_etop_dma_buffer_alloc(int len, int *byte_offset, void **opt) struct sk_buff *skb = NULL; skb = dev_alloc_skb(ETHERNET_PACKET_DMA_BUFFER_SIZE); - if(skb == NULL) + if (skb == NULL) return NULL; buffer = (unsigned char*)(skb->data); @@ -262,7 +266,7 @@ ifxmips_etop_dma_buffer_free(unsigned char *dataptr, void *opt) { struct sk_buff *skb = NULL; - if(opt == NULL) + if (opt == NULL) { kfree(dataptr); } else { @@ -280,12 +284,11 @@ ifxmips_get_stats(struct net_device *dev) static int ifxmips_mii_dev_init(struct net_device *dev) { - u64 retval = 0; int i; struct ifxmips_mii_priv *priv; ether_setup(dev); - printk(KERN_INFO DRVNAME ": %s is up\n", dev->name); + printk(KERN_INFO "ifxmips_mii0: %s is up\n", dev->name); dev->open = ifxmips_ifxmips_mii_open; dev->stop = ifxmips_mii_release; dev->hard_start_xmit = ifxmips_mii_tx; @@ -295,7 +298,7 @@ ifxmips_mii_dev_init(struct net_device *dev) memset(dev->priv, 0, sizeof(struct ifxmips_mii_priv)); priv = dev->priv; priv->dma_device = dma_device_reserve("PPE"); - if(!priv->dma_device){ + if (!priv->dma_device){ BUG(); return -ENODEV; } @@ -304,40 +307,26 @@ ifxmips_mii_dev_init(struct net_device *dev) priv->dma_device->intr_handler = &dma_intr_handler; priv->dma_device->max_rx_chan_num = 4; - for(i = 0; i < priv->dma_device->max_rx_chan_num; i++) + for (i = 0; i < priv->dma_device->max_rx_chan_num; i++) { priv->dma_device->rx_chan[i]->packet_size = ETHERNET_PACKET_DMA_BUFFER_SIZE; priv->dma_device->rx_chan[i]->control = IFXMIPS_DMA_CH_ON; } - for(i = 0; i < priv->dma_device->max_tx_chan_num; i++) - if(i == 0) + for (i = 0; i < priv->dma_device->max_tx_chan_num; i++) + if (i == 0) priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_ON; else priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_OFF; dma_device_register(priv->dma_device); - /*read the mac address from the mac table and put them into the mac table.*/ + printk(KERN_INFO "ifxmips_mii0: using mac="); for (i = 0; i < 6; i++) - retval += u_boot_ethaddr[i]; - - //TODO - /* ethaddr not set in u-boot ? */ - if(retval == 0) { - printk(KERN_INFO DRVNAME ": using default MAC address\n"); - dev->dev_addr[0] = 0x00; - dev->dev_addr[1] = 0x11; - dev->dev_addr[2] = 0x22; - dev->dev_addr[3] = 0x33; - dev->dev_addr[4] = 0x44; - dev->dev_addr[5] = 0x55; - } else { - for(i = 0; i < 6; i++) - dev->dev_addr[i] = u_boot_ethaddr[i]; + dev->dev_addr[i] = mac_addr[i]; + printk("%02X%c", dev->dev_addr[i], (i == 5)?('\n'):(':')); } - return 0; } @@ -347,10 +336,10 @@ ifxmips_mii_chip_init(int mode) ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_DMA); ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_PPE); - if(mode == REV_MII_MODE) - ifxmips_w32((ifxmips_r32(IFXMIPS_PPE32_CFG) & PPE32_MII_MASK) | PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG); - else if(mode == MII_MODE) - ifxmips_w32((ifxmips_r32(IFXMIPS_PPE32_CFG) & PPE32_MII_MASK) | PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG); + if (mode == REV_MII_MODE) + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG); + else if (mode == MII_MODE) + ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG); ifxmips_w32(PPE32_PLEN_UNDER | PPE32_PLEN_OVER, IFXMIPS_PPE32_IG_PLEN_CTRL); ifxmips_w32(PPE32_CGEN, IFXMIPS_PPE32_ENET_MAC_CFG); wmb(); @@ -360,20 +349,20 @@ static int ifxmips_mii_probe(struct platform_device *dev) { int result = 0; - + unsigned char *mac = (unsigned char*)dev->dev.platform_data; ifxmips_mii0_dev = alloc_etherdev(sizeof(struct ifxmips_mii_priv)); ifxmips_mii0_dev->init = ifxmips_mii_dev_init; + memcpy(mac_addr, mac, 6); strcpy(ifxmips_mii0_dev->name, "eth%d"); + ifxmips_mii_chip_init(REV_MII_MODE); result = register_netdev(ifxmips_mii0_dev); if (result) { - printk(KERN_INFO DRVNAME ": error %i registering device \"%s\"\n", result, ifxmips_mii0_dev->name); + printk(KERN_INFO "ifxmips_mii0: error %i registering device \"%s\"\n", result, ifxmips_mii0_dev->name); goto out; } - /* ifxmips eval kit connects the phy/switch in REV mode */ - ifxmips_mii_chip_init(REV_MII_MODE); - printk(KERN_INFO DRVNAME ": driver loaded!\n"); + printk(KERN_INFO "ifxmips_mii0: driver loaded!\n"); out: return result; @@ -384,7 +373,7 @@ ifxmips_mii_remove(struct platform_device *dev) { struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv*)ifxmips_mii0_dev->priv; - printk(KERN_INFO DRVNAME ": ifxmips_mii0 cleanup\n"); + printk(KERN_INFO "ifxmips_mii0: ifxmips_mii0 cleanup\n"); dma_device_unregister(priv->dma_device); dma_device_release(priv->dma_device); @@ -399,7 +388,7 @@ platform_driver ifxmips_mii_driver = { .probe = ifxmips_mii_probe, .remove = ifxmips_mii_remove, .driver = { - .name = DRVNAME, + .name = "ifxmips_mii0", .owner = THIS_MODULE, }, }; @@ -409,7 +398,7 @@ ifxmips_mii_init(void) { int ret = platform_driver_register(&ifxmips_mii_driver); if (ret) - printk(KERN_INFO DRVNAME ": Error registering platfom driver!"); + printk(KERN_INFO "ifxmips_mii0: Error registering platfom driver!"); return ret; }