Commit edf697a0 authored by Stephen Hemminger's avatar Stephen Hemminger

[PATCH] (2/6) smctr -- probe2

Convert the SMC tokenring driver to new probing.
parent fa0add7a
...@@ -412,9 +412,12 @@ static void __init ethif_probe2(int unit) ...@@ -412,9 +412,12 @@ static void __init ethif_probe2(int unit)
extern int ibmtr_probe(struct net_device *); extern int ibmtr_probe(struct net_device *);
extern int sk_isa_probe(struct net_device *); extern int sk_isa_probe(struct net_device *);
extern int proteon_probe(struct net_device *); extern int proteon_probe(struct net_device *);
extern int smctr_probe(struct net_device *); extern struct net_device *smctr_probe(int unit);
static struct devprobe2 tr_probes2[] __initdata = { static struct devprobe2 tr_probes2[] __initdata = {
#ifdef CONFIG_SMCTR
{smctr_probe, 0},
#endif
{NULL, 0}, {NULL, 0},
}; };
...@@ -438,9 +441,6 @@ static __init int trif_probe(int unit) ...@@ -438,9 +441,6 @@ static __init int trif_probe(int unit)
#endif #endif
#ifdef CONFIG_PROTEON #ifdef CONFIG_PROTEON
proteon_probe(dev) == 0 || proteon_probe(dev) == 0 ||
#endif
#ifdef CONFIG_SMCTR
smctr_probe(dev) == 0 ||
#endif #endif
0 ) 0 )
err = register_netdev(dev); err = register_netdev(dev);
......
...@@ -69,13 +69,6 @@ static const char cardname[] = "smctr"; ...@@ -69,13 +69,6 @@ static const char cardname[] = "smctr";
#define SMCTR_IO_EXTENT 20 #define SMCTR_IO_EXTENT 20
/* A zero-terminated list of I/O addresses to be probed. */
static unsigned int smctr_portlist[] __initdata = {
0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
0x320, 0x340, 0x360, 0x380,
0
};
#ifdef CONFIG_MCA #ifdef CONFIG_MCA
static unsigned int smctr_posid = 0x6ec6; static unsigned int smctr_posid = 0x6ec6;
#endif #endif
...@@ -219,7 +212,7 @@ static int smctr_open(struct net_device *dev); ...@@ -219,7 +212,7 @@ static int smctr_open(struct net_device *dev);
static int smctr_open_tr(struct net_device *dev); static int smctr_open_tr(struct net_device *dev);
/* P */ /* P */
int __init smctr_probe (struct net_device *dev); struct net_device *smctr_probe(int unit);
static int __init smctr_probe1(struct net_device *dev, int ioaddr); static int __init smctr_probe1(struct net_device *dev, int ioaddr);
static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size, static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
struct net_device *dev, __u16 rx_status); struct net_device *dev, __u16 rx_status);
...@@ -3591,71 +3584,72 @@ static int smctr_open_tr(struct net_device *dev) ...@@ -3591,71 +3584,72 @@ static int smctr_open_tr(struct net_device *dev)
return (err); return (err);
} }
/* Check for a network adapter of this type, and return '0 if one exists. /* Check for a network adapter of this type,
* If dev->base_addr == 0, probe all likely locations. * and return device structure if one exists.
* If dev->base_addr == 1, always return failure.
*/ */
int __init smctr_probe (struct net_device *dev) struct net_device __init *smctr_probe(int unit)
{ {
int i; struct net_device *dev = alloc_trdev(sizeof(struct net_local));
int base_addr; static const unsigned ports[] = {
0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
0x320, 0x340, 0x360, 0x380, 0
};
const unsigned *port;
int err = 0;
#ifndef MODULE if (!dev)
netdev_boot_setup_check(dev); return ERR_PTR(-ENOMEM);
tr_setup(dev);
#endif
base_addr = dev->base_addr; SET_MODULE_OWNER(dev);
if(base_addr > 0x1ff) /* Check a single specified location. */
return (smctr_probe1(dev, base_addr));
else if(base_addr != 0) /* Don't probe at all. */
return (-ENXIO);
for(i = 0; smctr_portlist[i]; i++) if (unit >= 0) {
{ sprintf(dev->name, "tr%d", unit);
int ioaddr = smctr_portlist[i]; netdev_boot_setup_check(dev);
if (!smctr_probe1(dev, ioaddr))
return (0);
} }
return (-ENODEV); if (dev->base_addr > 0x1ff) /* Check a single specified location. */
} err = smctr_probe1(dev, dev->base_addr);
else if(dev->base_addr != 0) /* Don't probe at all. */
static void cleanup_card(struct net_device *dev) err =-ENXIO;
{ else {
for (port = ports; *port; port++) {
err = smctr_probe1(dev, *port);
if (!err)
break;
}
}
if (err)
goto out;
err = register_netdev(dev);
if (err)
goto out1;
return dev;
out1:
#ifdef CONFIG_MCA #ifdef CONFIG_MCA
struct net_local *tp = (struct net_local *)dev->priv; { struct net_local *tp = (struct net_local *)dev->priv;
if (tp->slot_num) if (tp->slot_num)
mca_mark_as_unused(tp->slot_num); mca_mark_as_unused(tp->slot_num);
}
#endif #endif
release_region(dev->base_addr, SMCTR_IO_EXTENT); release_region(dev->base_addr, SMCTR_IO_EXTENT);
if (dev->irq)
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
if (dev->priv) out:
kfree(dev->priv); free_netdev(dev);
return ERR_PTR(err);
} }
static int __init smctr_probe1(struct net_device *dev, int ioaddr) static int __init smctr_probe1(struct net_device *dev, int ioaddr)
{ {
static unsigned version_printed; static unsigned version_printed;
struct net_local *tp; struct net_local *tp = dev->priv;
int err; int err;
__u32 *ram; __u32 *ram;
if(smctr_debug && version_printed++ == 0) if(smctr_debug && version_printed++ == 0)
printk(version); printk(version);
/* Setup this devices private information structure */
tp = (struct net_local *)kmalloc(sizeof(struct net_local),
GFP_KERNEL);
if(tp == NULL) {
err = -ENOMEM;
goto out;
}
memset(tp, 0, sizeof(struct net_local));
spin_lock_init(&tp->lock); spin_lock_init(&tp->lock);
dev->priv = tp;
dev->base_addr = ioaddr; dev->base_addr = ioaddr;
/* Actually detect an adapter now. */ /* Actually detect an adapter now. */
...@@ -3664,7 +3658,7 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr) ...@@ -3664,7 +3658,7 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr)
{ {
if ((err = smctr_chk_mca(dev)) < 0) { if ((err = smctr_chk_mca(dev)) < 0) {
err = -ENODEV; err = -ENODEV;
goto out_tp; goto out;
} }
} }
...@@ -3679,7 +3673,6 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr) ...@@ -3679,7 +3673,6 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr)
if(err != UCODE_PRESENT && err != SUCCESS) if(err != UCODE_PRESENT && err != SUCCESS)
{ {
printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err); printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
cleanup_card(dev);
err = -EIO; err = -EIO;
goto out; goto out;
} }
...@@ -3704,8 +3697,6 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr) ...@@ -3704,8 +3697,6 @@ static int __init smctr_probe1(struct net_device *dev, int ioaddr)
dev->set_multicast_list = &smctr_set_multicast_list; dev->set_multicast_list = &smctr_set_multicast_list;
return (0); return (0);
out_tp:
kfree(tp);
out: out:
return err; return err;
} }
...@@ -5677,47 +5668,59 @@ static int smctr_wait_while_cbusy(struct net_device *dev) ...@@ -5677,47 +5668,59 @@ static int smctr_wait_while_cbusy(struct net_device *dev)
static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS]; static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
static int io[SMCTR_MAX_ADAPTERS]; static int io[SMCTR_MAX_ADAPTERS];
static int irq[SMCTR_MAX_ADAPTERS]; static int irq[SMCTR_MAX_ADAPTERS];
static int mem[SMCTR_MAX_ADAPTERS];
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_PARM(io, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i"); MODULE_PARM(io, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
MODULE_PARM(irq, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i"); MODULE_PARM(irq, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
MODULE_PARM(mem, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i"); MODULE_PARM(ringspeed, "i");
MODULE_PARM(ringspeed, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
int init_module(void) static struct net_device *setup_card(int n)
{ {
int i; struct net_device *dev = alloc_trdev(sizeof(struct net_local));
int err;
for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
struct net_device *dev = alloc_trdev(0);
irq[i] = 0;
mem[i] = 0;
if (!dev) if (!dev)
return -ENOMEM; return ERR_PTR(-ENOMEM);
dev->base_addr = io[i];
dev->irq = irq[i];
dev->mem_start = mem[i];
if (smctr_probe(dev) != 0) { dev->irq = irq[n];
kfree(dev); err = smctr_probe1(dev, io[n]);
if (i == 0) { if (err)
printk(KERN_ERR "%s: smctr_probe failed.\n", goto out;
cardname);
return -EIO; err = register_netdev(dev);
} if (err)
return 0; goto out1;
} return dev;
if (register_netdev(dev) != 0) { out1:
cleanup_card(dev); #ifdef CONFIG_MCA
kfree(dev); { struct net_local *tp = (struct net_local *)dev->priv;
continue; if (tp->slot_num)
mca_mark_as_unused(tp->slot_num);
} }
#endif
release_region(dev->base_addr, SMCTR_IO_EXTENT);
free_irq(dev->irq, dev);
out:
free_netdev(dev);
return ERR_PTR(err);
}
int init_module(void)
{
int i, found = 0;
struct net_device *dev;
for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
dev = io[0]? setup_card(i) : smctr_probe(-1);
if (!IS_ERR(dev)) {
++found;
dev_smctr[i] = dev; dev_smctr[i] = dev;
} }
}
return (0); return found ? 0 : -ENODEV;
} }
void cleanup_module(void) void cleanup_module(void)
...@@ -5726,9 +5729,20 @@ void cleanup_module(void) ...@@ -5726,9 +5729,20 @@ void cleanup_module(void)
for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) { for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
struct net_device *dev = dev_smctr[i]; struct net_device *dev = dev_smctr[i];
if (dev) { if (dev) {
unregister_netdev(dev); unregister_netdev(dev);
cleanup_card(dev); #ifdef CONFIG_MCA
{ struct net_local *tp = dev->priv;
if (tp->slot_num)
mca_mark_as_unused(tp->slot_num);
}
#endif
release_region(dev->base_addr, SMCTR_IO_EXTENT);
if (dev->irq)
free_irq(dev->irq, dev);
free_netdev(dev); free_netdev(dev);
} }
} }
......
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