2007-12-20 22:29:45 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2008-06-23 20:31:34 +00:00
|
|
|
* Copyright (C) 2005 Wu Qi Ming <Qi-Ming.Wu@infineon.com>
|
|
|
|
* Copyright (C) 2008 John Crispin <blogic@openwrt.org>
|
2007-12-20 22:29:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/mm.h>
|
2007-12-25 12:38:15 +00:00
|
|
|
#include <linux/platform_device.h>
|
2007-12-20 22:29:45 +00:00
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <asm/checksum.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <asm/delay.h>
|
2007-12-22 13:55:14 +00:00
|
|
|
#include <asm/ifxmips/ifxmips.h>
|
|
|
|
#include <asm/ifxmips/ifxmips_dma.h>
|
|
|
|
#include <asm/ifxmips/ifxmips_pmu.h>
|
2007-12-20 22:29:45 +00:00
|
|
|
|
2008-07-05 23:06:07 +00:00
|
|
|
struct ifxmips_mii_priv {
|
|
|
|
struct net_device_stats stats;
|
|
|
|
struct dma_device_info *dma_device;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
};
|
|
|
|
|
2008-06-07 10:12:15 +00:00
|
|
|
static struct net_device *ifxmips_mii0_dev;
|
2008-06-29 00:42:45 +00:00
|
|
|
static unsigned char mac_addr[MAX_ADDR_LEN];
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
void
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_write_mdio(u32 phy_addr, u32 phy_reg, u16 phy_data)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
u32 val = MDIO_ACC_REQUEST |
|
|
|
|
((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
|
|
|
|
((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET) |
|
|
|
|
phy_data;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST);
|
2008-06-07 16:04:31 +00:00
|
|
|
ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
2008-06-29 14:56:45 +00:00
|
|
|
EXPORT_SYMBOL(ifxmips_write_mdio);
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
unsigned short
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_read_mdio(u32 phy_addr, u32 phy_reg)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
u32 val = MDIO_ACC_REQUEST | MDIO_ACC_READ |
|
|
|
|
((phy_addr & MDIO_ACC_ADDR_MASK) << MDIO_ACC_ADDR_OFFSET) |
|
|
|
|
((phy_reg & MDIO_ACC_REG_MASK) << MDIO_ACC_REG_OFFSET);
|
|
|
|
|
2008-07-05 23:06:07 +00:00
|
|
|
while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST);
|
2008-06-07 16:04:31 +00:00
|
|
|
ifxmips_w32(val, IFXMIPS_PPE32_MDIO_ACC);
|
2008-06-23 20:31:34 +00:00
|
|
|
while(ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_REQUEST){};
|
2008-06-07 16:04:31 +00:00
|
|
|
val = ifxmips_r32(IFXMIPS_PPE32_MDIO_ACC) & MDIO_ACC_VAL_MASK;
|
2007-12-20 22:29:45 +00:00
|
|
|
return val;
|
|
|
|
}
|
2008-06-29 14:56:45 +00:00
|
|
|
EXPORT_SYMBOL(ifxmips_read_mdio);
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_ifxmips_mii_open(struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv* priv = (struct ifxmips_mii_priv*)dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
struct dma_device_info* dma_dev = priv->dma_device;
|
|
|
|
int i;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < dma_dev->max_rx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-23 20:31:34 +00:00
|
|
|
if((dma_dev->rx_chan[i])->control == IFXMIPS_DMA_CH_ON)
|
2007-12-20 22:29:45 +00:00
|
|
|
(dma_dev->rx_chan[i])->open(dma_dev->rx_chan[i]);
|
|
|
|
}
|
|
|
|
netif_start_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_release(struct net_device *dev){
|
|
|
|
struct ifxmips_mii_priv* priv = (struct ifxmips_mii_priv*)dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
struct dma_device_info* dma_dev = priv->dma_device;
|
|
|
|
int i;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < dma_dev->max_rx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
dma_dev->rx_chan[i]->close(dma_dev->rx_chan[i]);
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_hw_receive(struct net_device* dev,struct dma_device_info* dma_dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv*)dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
unsigned char* buf = NULL;
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
len = dma_device_read(dma_dev, &buf, (void**)&skb);
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
if(len >= ETHERNET_PACKET_DMA_BUFFER_SIZE)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: packet too large %d\n",len);
|
2008-06-23 20:31:34 +00:00
|
|
|
goto ifxmips_mii_hw_receive_err_exit;
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove CRC */
|
|
|
|
len -= 4;
|
2008-06-23 20:31:34 +00:00
|
|
|
if(skb == NULL)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: cannot restore pointer\n");
|
2008-06-23 20:31:34 +00:00
|
|
|
goto ifxmips_mii_hw_receive_err_exit;
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
if(len > (skb->end - skb->tail))
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: BUG, len:%d end:%p tail:%p\n",
|
2008-06-23 20:31:34 +00:00
|
|
|
(len+4), skb->end, skb->tail);
|
|
|
|
goto ifxmips_mii_hw_receive_err_exit;
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_put(skb, len);
|
|
|
|
skb->dev = dev;
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
netif_rx(skb);
|
|
|
|
|
|
|
|
priv->stats.rx_packets++;
|
|
|
|
priv->stats.rx_bytes += len;
|
|
|
|
return 0;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_hw_receive_err_exit:
|
|
|
|
if(len == 0)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
if(skb)
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
priv->stats.rx_errors++;
|
|
|
|
priv->stats.rx_dropped++;
|
|
|
|
return -EIO;
|
|
|
|
} else {
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_hw_tx(char *buf, int len, struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv *priv = dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
struct dma_device_info* dma_dev = priv->dma_device;
|
|
|
|
ret = dma_device_write(dma_dev, buf, len, priv->skb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_tx(struct sk_buff *skb, struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *data;
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv *priv = dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
struct dma_device_info* dma_dev = priv->dma_device;
|
|
|
|
|
|
|
|
len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
|
|
|
|
data = skb->data;
|
|
|
|
priv->skb = skb;
|
|
|
|
dev->trans_start = jiffies;
|
|
|
|
// TODO we got more than 1 dma channel, so we should do something intelligent
|
|
|
|
// here to select one
|
|
|
|
dma_dev->current_tx_chan = 0;
|
|
|
|
|
|
|
|
wmb();
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
if(ifxmips_mii_hw_tx(data, len, dev) != len)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
priv->stats.tx_errors++;
|
|
|
|
priv->stats.tx_dropped++;
|
|
|
|
} else {
|
|
|
|
priv->stats.tx_packets++;
|
|
|
|
priv->stats.tx_bytes+=len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_tx_timeout(struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv* priv = (struct ifxmips_mii_priv*)dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
priv->stats.tx_errors++;
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < priv->dma_device->max_tx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
priv->dma_device->tx_chan[i]->disable_irq(priv->dma_device->tx_chan[i]);
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-06-23 20:31:34 +00:00
|
|
|
dma_intr_handler(struct dma_device_info* dma_dev, int status)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
switch(status)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
case RCV_INT:
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_hw_receive(ifxmips_mii0_dev, dma_dev);
|
2007-12-20 22:29:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TX_BUF_FULL_INT:
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: tx buffer full\n");
|
2008-06-07 10:12:15 +00:00
|
|
|
netif_stop_queue(ifxmips_mii0_dev);
|
2007-12-20 22:29:45 +00:00
|
|
|
for (i = 0; i < dma_dev->max_tx_chan_num; i++)
|
|
|
|
{
|
2007-12-22 00:17:22 +00:00
|
|
|
if ((dma_dev->tx_chan[i])->control==IFXMIPS_DMA_CH_ON)
|
2007-12-20 22:29:45 +00:00
|
|
|
dma_dev->tx_chan[i]->enable_irq(dma_dev->tx_chan[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRANSMIT_CPT_INT:
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < dma_dev->max_tx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
dma_dev->tx_chan[i]->disable_irq(dma_dev->tx_chan[i]);
|
|
|
|
|
2008-06-07 10:12:15 +00:00
|
|
|
netif_wake_queue(ifxmips_mii0_dev);
|
2007-12-20 22:29:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char*
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_etop_dma_buffer_alloc(int len, int *byte_offset, void **opt)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
unsigned char *buffer = NULL;
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
|
|
|
|
skb = dev_alloc_skb(ETHERNET_PACKET_DMA_BUFFER_SIZE);
|
2008-06-23 20:31:34 +00:00
|
|
|
if(skb == NULL)
|
2007-12-20 22:29:45 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buffer = (unsigned char*)(skb->data);
|
|
|
|
skb_reserve(skb, 2);
|
|
|
|
*(int*)opt = (int)skb;
|
|
|
|
*byte_offset = 2;
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_etop_dma_buffer_free(unsigned char *dataptr, void *opt)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
|
|
|
|
if(opt == NULL)
|
|
|
|
{
|
|
|
|
kfree(dataptr);
|
|
|
|
} else {
|
|
|
|
skb = (struct sk_buff*)opt;
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct net_device_stats*
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_get_stats(struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
return (struct net_device_stats *)dev->priv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_dev_init(struct net_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv *priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
ether_setup(dev);
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: %s is up\n", dev->name);
|
2008-06-23 20:31:34 +00:00
|
|
|
dev->open = ifxmips_ifxmips_mii_open;
|
|
|
|
dev->stop = ifxmips_mii_release;
|
|
|
|
dev->hard_start_xmit = ifxmips_mii_tx;
|
2007-12-22 13:55:14 +00:00
|
|
|
dev->get_stats = ifxmips_get_stats;
|
2008-06-23 20:31:34 +00:00
|
|
|
dev->tx_timeout = ifxmips_mii_tx_timeout;
|
2007-12-20 22:29:45 +00:00
|
|
|
dev->watchdog_timeo = 10 * HZ;
|
2008-06-23 20:31:34 +00:00
|
|
|
memset(dev->priv, 0, sizeof(struct ifxmips_mii_priv));
|
2007-12-20 22:29:45 +00:00
|
|
|
priv = dev->priv;
|
|
|
|
priv->dma_device = dma_device_reserve("PPE");
|
2008-06-23 20:31:34 +00:00
|
|
|
if(!priv->dma_device){
|
2007-12-20 22:29:45 +00:00
|
|
|
BUG();
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2007-12-22 13:55:14 +00:00
|
|
|
priv->dma_device->buffer_alloc = &ifxmips_etop_dma_buffer_alloc;
|
|
|
|
priv->dma_device->buffer_free = &ifxmips_etop_dma_buffer_free;
|
2007-12-20 22:29:45 +00:00
|
|
|
priv->dma_device->intr_handler = &dma_intr_handler;
|
|
|
|
priv->dma_device->max_rx_chan_num = 4;
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < priv->dma_device->max_rx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
priv->dma_device->rx_chan[i]->packet_size = ETHERNET_PACKET_DMA_BUFFER_SIZE;
|
2007-12-22 00:17:22 +00:00
|
|
|
priv->dma_device->rx_chan[i]->control = IFXMIPS_DMA_CH_ON;
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2008-06-23 20:31:34 +00:00
|
|
|
for(i = 0; i < priv->dma_device->max_tx_chan_num; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
if(i == 0)
|
2007-12-22 00:17:22 +00:00
|
|
|
priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_ON;
|
2007-12-20 22:29:45 +00:00
|
|
|
else
|
2007-12-22 00:17:22 +00:00
|
|
|
priv->dma_device->tx_chan[i]->control = IFXMIPS_DMA_CH_OFF;
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
dma_device_register(priv->dma_device);
|
|
|
|
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: using mac=");
|
|
|
|
for(i = 0; i < 6; i++)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-29 00:42:45 +00:00
|
|
|
dev->dev_addr[i] = mac_addr[i];
|
|
|
|
printk("%02X%c", dev->dev_addr[i], (i == 5)?('\n'):(':'));
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii_chip_init(int mode)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2007-12-22 13:55:14 +00:00
|
|
|
ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_DMA);
|
|
|
|
ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_PPE);
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
if(mode == REV_MII_MODE)
|
2008-06-29 00:42:45 +00:00
|
|
|
ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_REVERSE, IFXMIPS_PPE32_CFG);
|
2007-12-20 22:29:45 +00:00
|
|
|
else if(mode == MII_MODE)
|
2008-06-29 00:42:45 +00:00
|
|
|
ifxmips_w32_mask(PPE32_MII_MASK, PPE32_MII_NORMAL, IFXMIPS_PPE32_CFG);
|
2008-06-07 16:04:31 +00:00
|
|
|
ifxmips_w32(PPE32_PLEN_UNDER | PPE32_PLEN_OVER, IFXMIPS_PPE32_IG_PLEN_CTRL);
|
|
|
|
ifxmips_w32(PPE32_CGEN, IFXMIPS_PPE32_ENET_MAC_CFG);
|
2007-12-20 22:29:45 +00:00
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
|
2007-12-25 12:38:15 +00:00
|
|
|
static int
|
|
|
|
ifxmips_mii_probe(struct platform_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
2008-07-05 23:06:07 +00:00
|
|
|
unsigned char *mac = (unsigned char*)dev->dev.platform_data;
|
2008-06-23 20:31:34 +00:00
|
|
|
ifxmips_mii0_dev = alloc_etherdev(sizeof(struct ifxmips_mii_priv));
|
|
|
|
ifxmips_mii0_dev->init = ifxmips_mii_dev_init;
|
2008-07-05 23:06:07 +00:00
|
|
|
memcpy(mac_addr, mac, 6);
|
2008-06-07 10:12:15 +00:00
|
|
|
strcpy(ifxmips_mii0_dev->name, "eth%d");
|
2008-06-29 14:56:45 +00:00
|
|
|
ifxmips_mii_chip_init(REV_MII_MODE);
|
2008-06-07 10:12:15 +00:00
|
|
|
result = register_netdev(ifxmips_mii0_dev);
|
2007-12-20 22:29:45 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: error %i registering device \"%s\"\n", result, ifxmips_mii0_dev->name);
|
2007-12-20 22:29:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: driver loaded!\n");
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-12-25 12:38:15 +00:00
|
|
|
static int
|
|
|
|
ifxmips_mii_remove(struct platform_device *dev)
|
2007-12-20 22:29:45 +00:00
|
|
|
{
|
2008-06-23 20:31:34 +00:00
|
|
|
struct ifxmips_mii_priv *priv = (struct ifxmips_mii_priv*)ifxmips_mii0_dev->priv;
|
2007-12-20 22:29:45 +00:00
|
|
|
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: ifxmips_mii0 cleanup\n");
|
2007-12-20 22:29:45 +00:00
|
|
|
|
|
|
|
dma_device_unregister(priv->dma_device);
|
|
|
|
dma_device_release(priv->dma_device);
|
|
|
|
kfree(priv->dma_device);
|
2008-06-07 10:12:15 +00:00
|
|
|
kfree(ifxmips_mii0_dev->priv);
|
|
|
|
unregister_netdev(ifxmips_mii0_dev);
|
2007-12-25 12:38:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-07 10:12:15 +00:00
|
|
|
static struct
|
|
|
|
platform_driver ifxmips_mii_driver = {
|
|
|
|
.probe = ifxmips_mii_probe,
|
|
|
|
.remove = ifxmips_mii_remove,
|
|
|
|
.driver = {
|
2008-06-29 00:42:45 +00:00
|
|
|
.name = "ifxmips_mii0",
|
2008-06-07 10:12:15 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
2007-12-25 12:38:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int __init
|
|
|
|
ifxmips_mii_init(void)
|
|
|
|
{
|
2008-06-07 10:12:15 +00:00
|
|
|
int ret = platform_driver_register(&ifxmips_mii_driver);
|
|
|
|
if (ret)
|
2008-06-29 00:42:45 +00:00
|
|
|
printk(KERN_INFO "ifxmips_mii0: Error registering platfom driver!");
|
2008-06-07 10:12:15 +00:00
|
|
|
return ret;
|
2007-12-25 12:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
ifxmips_mii_cleanup(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&ifxmips_mii_driver);
|
2007-12-20 22:29:45 +00:00
|
|
|
}
|
|
|
|
|
2007-12-25 12:38:15 +00:00
|
|
|
module_init(ifxmips_mii_init);
|
|
|
|
module_exit(ifxmips_mii_cleanup);
|
2008-06-23 20:31:34 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
|
|
|
|
MODULE_DESCRIPTION("ethernet map driver for IFXMIPS boards");
|