Commit a56fc3a9 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (04/12) Probe2 -- ni52

>From viro NE15-ni52
	* switched ni52 to dynamic allocation
	* ni52: embedded ->priv
	* ni52: fixed clobbering of everything on autoprobe
Additional:
	* add free_netdev
parent 461d5019
...@@ -69,7 +69,7 @@ extern int es_probe(struct net_device *); ...@@ -69,7 +69,7 @@ extern int es_probe(struct net_device *);
extern int lne390_probe(struct net_device *); extern int lne390_probe(struct net_device *);
extern int e2100_probe(struct net_device *); extern int e2100_probe(struct net_device *);
extern int ni5010_probe(struct net_device *); extern int ni5010_probe(struct net_device *);
extern int ni52_probe(struct net_device *); extern struct net_device *ni52_probe(int unit);
extern struct net_device *ni65_probe(int unit); extern struct net_device *ni65_probe(int unit);
extern int sonic_probe(struct net_device *); extern int sonic_probe(struct net_device *);
extern int SK_init(struct net_device *); extern int SK_init(struct net_device *);
...@@ -282,14 +282,14 @@ static struct devprobe isa_probes[] __initdata = { ...@@ -282,14 +282,14 @@ static struct devprobe isa_probes[] __initdata = {
#endif #endif
#ifdef CONFIG_NI5010 #ifdef CONFIG_NI5010
{ni5010_probe, 0}, {ni5010_probe, 0},
#endif
#ifdef CONFIG_NI52
{ni52_probe, 0},
#endif #endif
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe2 isa_probes2[] __initdata = { static struct devprobe2 isa_probes2[] __initdata = {
#ifdef CONFIG_NI52
{ni52_probe, 0},
#endif
#ifdef CONFIG_NI65 #ifdef CONFIG_NI65
{ni65_probe, 0}, {ni65_probe, 0},
#endif #endif
......
...@@ -354,50 +354,76 @@ static void alloc586(struct net_device *dev) ...@@ -354,50 +354,76 @@ static void alloc586(struct net_device *dev)
memset((char *)p->scb,0,sizeof(struct scb_struct)); memset((char *)p->scb,0,sizeof(struct scb_struct));
} }
/* set: io,irq,memstart,memend or set it when calling insmod */
static int irq=9;
static int io=0x300;
static long memstart; /* e.g 0xd0000 */
static long memend; /* e.g 0xd4000 */
/********************************************** /**********************************************
* probe the ni5210-card * probe the ni5210-card
*/ */
int __init ni52_probe(struct net_device *dev) struct net_device * __init ni52_probe(int unit)
{ {
#ifndef MODULE struct net_device *dev = alloc_etherdev(sizeof(struct priv));
int *port;
static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0}; static int ports[] = {0x300, 0x280, 0x360 , 0x320 , 0x340, 0};
#endif int *port;
int base_addr = dev->base_addr; int err = 0;
if (!dev)
return ERR_PTR(-ENOMEM);
if (unit >= 0) {
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
io = dev->base_addr;
irq = dev->irq;
memstart = dev->mem_start;
memend = dev->mem_end;
}
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
if (base_addr > 0x1ff) /* Check a single specified location. */ if (io > 0x1ff) { /* Check a single specified location. */
return ni52_probe1(dev, base_addr); err = ni52_probe1(dev, io);
else if (base_addr > 0) /* Don't probe at all. */ } else if (io > 0) { /* Don't probe at all. */
return -ENXIO; err = -ENXIO;
} else {
#ifdef MODULE for (port = ports; *port && ni52_probe1(dev, *port) ; port++)
printk("%s: no autoprobing allowed for modules.\n",dev->name); ;
#else if (*port)
for (port = ports; *port; port++) { goto got_it;
int ioaddr = *port;
dev->base_addr = ioaddr;
if (ni52_probe1(dev, ioaddr) == 0)
return 0;
}
#ifdef FULL_IO_PROBE #ifdef FULL_IO_PROBE
for(dev->base_addr=0x200; dev->base_addr<0x400; dev->base_addr+=8) for (io = 0x200; io < 0x400 && ni52_probe1(dev, io); io += 8)
if (ni52_probe1(dev, dev->base_addr) == 0) ;
return 0; if (io < 0x400)
#endif goto got_it;
#endif #endif
err = -ENODEV;
dev->base_addr = base_addr; }
return -ENODEV; if (err)
goto out;
got_it:
err = register_netdev(dev);
if (err)
goto out1;
return dev;
out1:
release_region(dev->base_addr, NI52_TOTAL_SIZE);
out:
free_netdev(dev);
return ERR_PTR(err);
} }
static int __init ni52_probe1(struct net_device *dev,int ioaddr) static int __init ni52_probe1(struct net_device *dev,int ioaddr)
{ {
int i, size, retval; int i, size, retval;
dev->base_addr = ioaddr;
dev->irq = irq;
dev->mem_start = memstart;
dev->mem_end = memend;
if (!request_region(ioaddr, NI52_TOTAL_SIZE, dev->name)) if (!request_region(ioaddr, NI52_TOTAL_SIZE, dev->name))
return -EBUSY; return -EBUSY;
...@@ -416,7 +442,7 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr) ...@@ -416,7 +442,7 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
goto out; goto out;
} }
printk("%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr); printk(KERN_INFO "%s: NI5210 found at %#3lx, ",dev->name,dev->base_addr);
/* /*
* check (or search) IO-Memory, 8K and 16K * check (or search) IO-Memory, 8K and 16K
...@@ -469,13 +495,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr) ...@@ -469,13 +495,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */ dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
#endif #endif
dev->priv = (void *) kmalloc(sizeof(struct priv),GFP_KERNEL);
if(dev->priv == NULL) {
printk("%s: Ooops .. can't allocate private driver memory.\n",dev->name);
retval = -ENOMEM;
goto out;
}
/* warning: we don't free it on errors */
memset((char *) dev->priv,0,sizeof(struct priv)); memset((char *) dev->priv,0,sizeof(struct priv));
((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size; ((struct priv *) (dev->priv))->memtop = isa_bus_to_virt(dev->mem_start) + size;
...@@ -503,8 +522,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr) ...@@ -503,8 +522,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
if(!dev->irq) if(!dev->irq)
{ {
printk("?autoirq, Failed to detect IRQ line!\n"); printk("?autoirq, Failed to detect IRQ line!\n");
kfree(dev->priv);
dev->priv = NULL;
retval = -EAGAIN; retval = -EAGAIN;
goto out; goto out;
} }
...@@ -526,8 +543,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr) ...@@ -526,8 +543,6 @@ static int __init ni52_probe1(struct net_device *dev,int ioaddr)
dev->if_port = 0; dev->if_port = 0;
ether_setup(dev);
return 0; return 0;
out: out:
release_region(ioaddr, NI52_TOTAL_SIZE); release_region(ioaddr, NI52_TOTAL_SIZE);
...@@ -1295,13 +1310,7 @@ static void set_multicast_list(struct net_device *dev) ...@@ -1295,13 +1310,7 @@ static void set_multicast_list(struct net_device *dev)
} }
#ifdef MODULE #ifdef MODULE
static struct net_device dev_ni52; static struct net_device *dev_ni52;
/* set: io,irq,memstart,memend or set it when calling insmod */
static int irq=9;
static int io=0x300;
static long memstart; /* e.g 0xd0000 */
static long memend; /* e.g 0xd4000 */
MODULE_PARM(io, "i"); MODULE_PARM(io, "i");
MODULE_PARM(irq, "i"); MODULE_PARM(irq, "i");
...@@ -1318,22 +1327,17 @@ int init_module(void) ...@@ -1318,22 +1327,17 @@ int init_module(void)
printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n"); printk("ni52: Autoprobing not allowed for modules.\nni52: Set symbols 'io' 'irq' 'memstart' and 'memend'\n");
return -ENODEV; return -ENODEV;
} }
dev_ni52.init = ni52_probe; dev_ni52 = ni52_probe(-1);
dev_ni52.irq = irq; if (IS_ERR(dev_ni52))
dev_ni52.base_addr = io; return PTR_ERR(dev_ni52);
dev_ni52.mem_end = memend;
dev_ni52.mem_start = memstart;
if (register_netdev(&dev_ni52) != 0)
return -EIO;
return 0; return 0;
} }
void cleanup_module(void) void cleanup_module(void)
{ {
release_region(dev_ni52.base_addr, NI52_TOTAL_SIZE); unregister_netdev(dev_ni52);
unregister_netdev(&dev_ni52); release_region(dev_ni52->base_addr, NI52_TOTAL_SIZE);
kfree(dev_ni52.priv); free_netdev(dev_ni52);
dev_ni52.priv = NULL;
} }
#endif /* MODULE */ #endif /* MODULE */
......
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