Commit 2a550512 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (2/12) Probe2 -- de620

Rework de620 driver to new dynamic allocation
Originally by Al Viro.
	* switched de620 to dynamic allocation
	* de620: embedded ->priv
	* de620: fixed IO before request_region()

Updated to ~jgarzik/net-drivers-2.5-exp
parent 37b91f25
...@@ -96,7 +96,7 @@ extern struct net_device *cops_probe(int unit); ...@@ -96,7 +96,7 @@ extern struct net_device *cops_probe(int unit);
extern struct net_device *ltpc_probe(void); extern struct net_device *ltpc_probe(void);
/* Detachable devices ("pocket adaptors") */ /* Detachable devices ("pocket adaptors") */
extern int de620_probe(struct net_device *); extern struct net_device *de620_probe(int unit);
/* Fibre Channel adapters */ /* Fibre Channel adapters */
extern int iph5526_probe(struct net_device *dev); extern int iph5526_probe(struct net_device *dev);
...@@ -292,7 +292,7 @@ static struct devprobe isa_probes[] __initdata = { ...@@ -292,7 +292,7 @@ static struct devprobe isa_probes[] __initdata = {
{NULL, 0}, {NULL, 0},
}; };
static struct devprobe parport_probes[] __initdata = { static struct devprobe2 parport_probes[] __initdata = {
#ifdef CONFIG_DE620 /* D-Link DE-620 adapter */ #ifdef CONFIG_DE620 /* D-Link DE-620 adapter */
{de620_probe, 0}, {de620_probe, 0},
#endif #endif
...@@ -383,8 +383,7 @@ static int __init ethif_probe(int unit) ...@@ -383,8 +383,7 @@ static int __init ethif_probe(int unit)
probe_list(dev, mips_probes) == 0 || probe_list(dev, mips_probes) == 0 ||
probe_list(dev, eisa_probes) == 0 || probe_list(dev, eisa_probes) == 0 ||
probe_list(dev, mca_probes) == 0 || probe_list(dev, mca_probes) == 0 ||
probe_list(dev, isa_probes) == 0 || probe_list(dev, isa_probes) == 0)
probe_list(dev, parport_probes) == 0)
err = register_netdev(dev); err = register_netdev(dev);
if (err) if (err)
...@@ -400,7 +399,7 @@ static void __init ethif_probe2(int unit) ...@@ -400,7 +399,7 @@ static void __init ethif_probe2(int unit)
if (base_addr == 1) if (base_addr == 1)
return; return;
return; /* nothing yet */ probe_list2(unit, parport_probes, base_addr == 0);
} }
#ifdef CONFIG_TR #ifdef CONFIG_TR
......
...@@ -226,7 +226,6 @@ static int de620_rx_intr(struct net_device *); ...@@ -226,7 +226,6 @@ static int de620_rx_intr(struct net_device *);
/* Initialization */ /* Initialization */
static int adapter_init(struct net_device *); static int adapter_init(struct net_device *);
int de620_probe(struct net_device *);
static int read_eeprom(struct net_device *); static int read_eeprom(struct net_device *);
...@@ -814,11 +813,16 @@ static int adapter_init(struct net_device *dev) ...@@ -814,11 +813,16 @@ static int adapter_init(struct net_device *dev)
* *
* Check if there is a DE-620 connected * Check if there is a DE-620 connected
*/ */
int __init de620_probe(struct net_device *dev) struct net_device * __init de620_probe(int unit)
{ {
static struct net_device_stats de620_netstats;
int i;
byte checkbyte = 0xa5; byte checkbyte = 0xa5;
struct net_device *dev;
int err = -ENOMEM;
int i;
dev = alloc_etherdev(sizeof(struct net_device_stats));
if (!dev)
goto out;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
...@@ -831,11 +835,23 @@ int __init de620_probe(struct net_device *dev) ...@@ -831,11 +835,23 @@ int __init de620_probe(struct net_device *dev)
dev->base_addr = io; dev->base_addr = io;
dev->irq = irq; dev->irq = irq;
/* allow overriding parameters on command line */
if (unit >= 0) {
sprintf(dev->name, "eth%d", unit);
netdev_boot_setup_check(dev);
}
if (de620_debug) if (de620_debug)
printk(version); printk(version);
printk(KERN_INFO "D-Link DE-620 pocket adapter"); printk(KERN_INFO "D-Link DE-620 pocket adapter");
if (!request_region(dev->base_addr, 3, "de620")) {
printk(" io 0x%3lX, which is busy.\n", dev->base_addr);
err = -EBUSY;
goto out1;
}
/* Initially, configure basic nibble mode, so we can read the EEPROM */ /* Initially, configure basic nibble mode, so we can read the EEPROM */
NIC_Cmd = DEF_NIC_CMD; NIC_Cmd = DEF_NIC_CMD;
de620_set_register(dev, W_EIP, EIPRegister); de620_set_register(dev, W_EIP, EIPRegister);
...@@ -846,12 +862,8 @@ int __init de620_probe(struct net_device *dev) ...@@ -846,12 +862,8 @@ int __init de620_probe(struct net_device *dev)
if ((checkbyte != 0xa5) || (read_eeprom(dev) != 0)) { if ((checkbyte != 0xa5) || (read_eeprom(dev) != 0)) {
printk(" not identified in the printer port\n"); printk(" not identified in the printer port\n");
return -ENODEV; err = -ENODEV;
} goto out2;
if (!request_region(dev->base_addr, 3, "de620")) {
printk(KERN_ERR "io 0x%3lX, which is busy.\n", dev->base_addr);
return -EBUSY;
} }
/* else, got it! */ /* else, got it! */
...@@ -870,10 +882,6 @@ int __init de620_probe(struct net_device *dev) ...@@ -870,10 +882,6 @@ int __init de620_probe(struct net_device *dev)
else else
printk(" UTP)\n"); printk(" UTP)\n");
/* Initialize the device structure. */
dev->priv = &de620_netstats;
memset(dev->priv, 0, sizeof(struct net_device_stats));
dev->get_stats = get_stats; dev->get_stats = get_stats;
dev->open = de620_open; dev->open = de620_open;
dev->stop = de620_close; dev->stop = de620_close;
...@@ -884,8 +892,6 @@ int __init de620_probe(struct net_device *dev) ...@@ -884,8 +892,6 @@ int __init de620_probe(struct net_device *dev)
/* base_addr and irq are already set, see above! */ /* base_addr and irq are already set, see above! */
ether_setup(dev);
/* dump eeprom */ /* dump eeprom */
if (de620_debug) { if (de620_debug) {
printk("\nEEPROM contents:\n"); printk("\nEEPROM contents:\n");
...@@ -899,7 +905,17 @@ int __init de620_probe(struct net_device *dev) ...@@ -899,7 +905,17 @@ int __init de620_probe(struct net_device *dev)
printk("SCR = 0x%02x\n", nic_data.SCR); printk("SCR = 0x%02x\n", nic_data.SCR);
} }
return 0; err = register_netdev(dev);
if (err)
goto out2;
return dev;
out2:
release_region(dev->base_addr, 3);
out1:
free_netdev(dev);
out:
return ERR_PTR(err);
} }
/********************************** /**********************************
...@@ -994,20 +1010,21 @@ static int __init read_eeprom(struct net_device *dev) ...@@ -994,20 +1010,21 @@ static int __init read_eeprom(struct net_device *dev)
* *
*/ */
#ifdef MODULE #ifdef MODULE
static struct net_device de620_dev; static struct net_device *de620_dev;
int init_module(void) int init_module(void)
{ {
de620_dev.init = de620_probe; de620_dev = de620_probe(-1);
if (register_netdev(&de620_dev) != 0) if (IS_ERR(de620_dev))
return -EIO; return PTR_ERR(de620_dev);
return 0; return 0;
} }
void cleanup_module(void) void cleanup_module(void)
{ {
unregister_netdev(&de620_dev); unregister_netdev(de620_dev);
release_region(de620_dev.base_addr, 3); release_region(de620_dev->base_addr, 3);
free_netdev(de620_dev);
} }
#endif /* MODULE */ #endif /* MODULE */
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
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