Commit 6857d83f authored by Russell King's avatar Russell King

[netdrvr ARM] alloc_etherdev updates

parent cd522168
...@@ -657,7 +657,7 @@ static int __init am79c961_init(void) ...@@ -657,7 +657,7 @@ static int __init am79c961_init(void)
struct dev_priv *priv; struct dev_priv *priv;
int i, ret; int i, ret;
dev = init_etherdev(NULL, sizeof(struct dev_priv)); dev = alloc_etherdev(sizeof(struct dev_priv));
ret = -ENOMEM; ret = -ENOMEM;
if (!dev) if (!dev)
goto out; goto out;
...@@ -715,12 +715,13 @@ static int __init am79c961_init(void) ...@@ -715,12 +715,13 @@ static int __init am79c961_init(void)
dev->set_multicast_list = am79c961_setmulticastlist; dev->set_multicast_list = am79c961_setmulticastlist;
dev->tx_timeout = am79c961_timeout; dev->tx_timeout = am79c961_timeout;
ret = register_netdev(dev);
if (ret == 0)
return 0; return 0;
release: release:
release_region(dev->base_addr, 0x18); release_region(dev->base_addr, 0x18);
nodev: nodev:
unregister_netdev(dev);
kfree(dev); kfree(dev);
out: out:
return ret; return ret;
......
...@@ -706,16 +706,6 @@ static int ether00_open(struct net_device* dev) ...@@ -706,16 +706,6 @@ static int ether00_open(struct net_device* dev)
if (!is_valid_ether_addr(dev->dev_addr)) if (!is_valid_ether_addr(dev->dev_addr))
return -EINVAL; return -EINVAL;
/* Allocate private memory */
dev->priv=kmalloc(sizeof(struct net_priv),GFP_KERNEL);
if(!dev->priv)
return -ENOMEM;
memset(dev->priv,0,sizeof(struct net_priv));
priv=(struct net_priv*)dev->priv;
priv->tq_memupdate.routine=ether00_mem_update;
priv->tq_memupdate.data=(void*) dev;
spin_lock_init(&priv->rx_lock);
/* Install interrupt handlers */ /* Install interrupt handlers */
result=request_irq(dev->irq,ether00_int,0,"ether00",dev); result=request_irq(dev->irq,ether00_int,0,"ether00",dev);
if(result) if(result)
...@@ -772,7 +762,6 @@ static int ether00_open(struct net_device* dev) ...@@ -772,7 +762,6 @@ static int ether00_open(struct net_device* dev)
open_err2: open_err2:
free_irq(dev->irq,dev); free_irq(dev->irq,dev);
open_err1: open_err1:
kfree(dev->priv);
return result; return result;
} }
...@@ -848,7 +837,6 @@ static int ether00_stop(struct net_device* dev) ...@@ -848,7 +837,6 @@ static int ether00_stop(struct net_device* dev)
free_irq(dev->irq,dev); free_irq(dev->irq,dev);
free_irq(2,dev); free_irq(2,dev);
iounmap(priv->dma_data); iounmap(priv->dma_data);
kfree(priv);
return 0; return 0;
} }
...@@ -901,23 +889,6 @@ static void ether00_get_ethernet_address(struct net_device* dev) ...@@ -901,23 +889,6 @@ static void ether00_get_ethernet_address(struct net_device* dev)
} }
static int ether00_init(struct net_device* dev)
{
ether_setup(dev);
dev->open=ether00_open;
dev->stop=ether00_stop;
dev->set_multicast_list=ether00_set_multicast;
dev->hard_start_xmit=ether00_tx;
dev->get_stats=ether00_stats;
ether00_get_ethernet_address(dev);
SET_MODULE_OWNER(dev);
return 0;
}
/* /*
* Keep a mapping of dev_info addresses -> port lines to use when * Keep a mapping of dev_info addresses -> port lines to use when
* removing ports dev==NULL indicates unused entry * removing ports dev==NULL indicates unused entry
...@@ -929,13 +900,13 @@ static struct net_device* dev_list[ETH_NR]; ...@@ -929,13 +900,13 @@ static struct net_device* dev_list[ETH_NR];
static int ether00_add_device(struct pldhs_dev_info* dev_info,void* dev_ps_data) static int ether00_add_device(struct pldhs_dev_info* dev_info,void* dev_ps_data)
{ {
struct net_device *dev; struct net_device *dev;
struct net_priv *priv;
void *map_addr; void *map_addr;
int result; int result;
int i; int i;
i=0; i=0;
while(dev_list[i]) while(dev_list[i] && i < ETH_NR)
i++; i++;
if(i==ETH_NR){ if(i==ETH_NR){
...@@ -944,37 +915,61 @@ static int ether00_add_device(struct pldhs_dev_info* dev_info,void* dev_ps_data) ...@@ -944,37 +915,61 @@ static int ether00_add_device(struct pldhs_dev_info* dev_info,void* dev_ps_data)
} }
dev=kmalloc(sizeof(struct net_device),GFP_KERNEL); if (!request_mem_region(dev_info->base_addr, MAC_REG_SIZE, "ether00"))
if(!dev){ return -EBUSY;
return -ENOMEM;
dev = alloc_etherdev(sizeof(struct net_priv));
if(!dev) {
result = -ENOMEM;
goto out_release;
} }
memset(dev,0,sizeof(struct net_device)); memset(dev,0,sizeof(struct net_device));
memset(dev->priv, 0, sizeof(struct net_priv));
priv = dev->priv;
priv->tq_memupdate.routine=ether00_mem_update;
priv->tq_memupdate.data=(void*) dev;
spin_lock_init(&priv->rx_lock);
map_addr=ioremap_nocache(dev_info->base_addr,SZ_4K); map_addr=ioremap_nocache(dev_info->base_addr,SZ_4K);
if(!map_addr){ if(!map_addr){
return -ENOMEM; result = -ENOMEM;
out_kfree;
} }
dev->init=ether00_init; dev->open=ether00_open;
strcpy(dev->name,"eth%d"); dev->stop=ether00_stop;
dev->set_multicast_list=ether00_set_multicast;
dev->hard_start_xmit=ether00_tx;
dev->get_stats=ether00_stats;
ether00_get_ethernet_address(dev);
SET_MODULE_OWNER(dev);
dev->base_addr=(unsigned int)map_addr; dev->base_addr=(unsigned int)map_addr;
dev->irq=dev_info->irq; dev->irq=dev_info->irq;
dev->features=NETIF_F_DYNALLOC | NETIF_F_HW_CSUM; dev->features=NETIF_F_DYNALLOC | NETIF_F_HW_CSUM;
if(check_mem_region((unsigned int)map_addr, MAC_REG_SIZE)){
return -EBUSY;
}
request_mem_region((unsigned int)map_addr, MAC_REG_SIZE, "ether00");
result=register_netdev(dev); result=register_netdev(dev);
if(result){ if(result){
printk("Ether00: Error %i registering driver\n",result); printk("Ether00: Error %i registering driver\n",result);
return result; goto out_unmap;
} }
printk("registered ether00 device at %#x\n",dev_info->base_addr); printk("registered ether00 device at %#x\n",dev_info->base_addr);
dev_list[i]=dev; dev_list[i]=dev;
return result; return result;
out_unmap:
iounmap(map_addr);
out_kfree:
kfree(dev);
out_release:
release_mem_region(dev_info->base_addr, MAC_REG_SIZE);
return result;
} }
......
...@@ -722,7 +722,7 @@ ether1_sendpacket (struct sk_buff *skb, struct net_device *dev) ...@@ -722,7 +722,7 @@ ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
tx.tx_command = CMD_TX | CMD_INTR; tx.tx_command = CMD_TX | CMD_INTR;
tx.tx_link = nopaddr; tx.tx_link = nopaddr;
tx.tx_tbdoffset = tbdaddr; tx.tx_tbdoffset = tbdaddr;
tbd.tbd_opts = TBD_EOL | len; tbd.tbd_opts = TBD_EOL | skb->len;
tbd.tbd_link = I82586_NULL; tbd.tbd_link = I82586_NULL;
tbd.tbd_bufl = dataddr; tbd.tbd_bufl = dataddr;
tbd.tbd_bufh = 0; tbd.tbd_bufh = 0;
...@@ -1013,7 +1013,7 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -1013,7 +1013,7 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
ether1_banner(); ether1_banner();
dev = init_etherdev(NULL, sizeof(struct ether1_priv)); dev = alloc_etherdev(sizeof(struct ether1_priv));
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1057,13 +1057,16 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -1057,13 +1057,16 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
dev->tx_timeout = ether1_timeout; dev->tx_timeout = ether1_timeout;
dev->watchdog_timeo = 5 * HZ / 100; dev->watchdog_timeo = 5 * HZ / 100;
ret = register_netdev(dev);
if (ret)
goto release;
ecard_set_drvdata(ec, dev); ecard_set_drvdata(ec, dev);
return 0; return 0;
release: release:
release_region(dev->base_addr, 16); release_region(dev->base_addr, 16);
release_region(dev->base_addr + 0x800, 4096); release_region(dev->base_addr + 0x800, 4096);
unregister_netdev(dev);
kfree(dev); kfree(dev);
out: out:
return ret; return ret;
......
...@@ -822,7 +822,7 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -822,7 +822,7 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id)
ether3_banner(); ether3_banner();
dev = init_etherdev(NULL, sizeof(struct dev_priv)); dev = alloc_etherdev(sizeof(struct dev_priv));
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -898,13 +898,16 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -898,13 +898,16 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id)
dev->tx_timeout = ether3_timeout; dev->tx_timeout = ether3_timeout;
dev->watchdog_timeo = 5 * HZ / 100; dev->watchdog_timeo = 5 * HZ / 100;
ret = register_netdev(dev);
if (ret)
goto failed;
ecard_set_drvdata(ec, dev); ecard_set_drvdata(ec, dev);
return 0; return 0;
failed: failed:
release_region(dev->base_addr, 128); release_region(dev->base_addr, 128);
free: free:
unregister_netdev(dev);
kfree(dev); kfree(dev);
out: out:
return ret; return ret;
......
...@@ -551,14 +551,14 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -551,14 +551,14 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
etherh_banner(); etherh_banner();
dev = init_etherdev(NULL, sizeof(struct etherh_priv)); dev = alloc_etherdev(sizeof(struct etherh_priv));
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
/* /*
* init_etherdev allocs and zeros dev->priv * alloc_etherdev allocs and zeros dev->priv
*/ */
eh = dev->priv; eh = dev->priv;
...@@ -694,17 +694,19 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -694,17 +694,19 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
etherh_reset(dev); etherh_reset(dev);
NS8390_init(dev, 0); NS8390_init(dev, 0);
ret = register_netdev(dev);
if (ret)
goto release;
ecard_set_drvdata(ec, dev); ecard_set_drvdata(ec, dev);
return 0; return 0;
release: release:
release_region(dev->base_addr, 16); release_region(dev->base_addr, 16);
free: free:
unregister_netdev(dev);
kfree(dev->priv);
kfree(dev); kfree(dev);
out: out:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment