EtherExpress PRO modularized patch (against 2.1.14)

Frank Breure (breure@serc.nl)
Tue, 3 Dec 1996 11:02:25 GMT


--Multipart_Tue_Dec__3_11:02:22_1996-1
Content-Type: text/plain; charset=US-ASCII

Hello fellow kernel hackers,

when trying to run 2.1.14 with the EtherExpress Pro driver as a
module I could not get things to work. I looked at the source and
saw that the module initialization in eepro.c was different from other
ethernet cards (i.e. 3c509.c, a card I have in another computer).

So, I took the `init_module' and `cleanup_module' functions from
`3c509.c' and modified them to do the `eepro' initialization, and, it
works (at least for me it does!).

Is the interface between the module utils and the drivers described
somewhere ? I think that the problem was basically in the following
declarations:
static int io = 0x200;
static int irq = 0;
static int mem = (RCV_RAM/1024); /* Size of the rx buffer in KB */

against:

static int io[MAX_EEPRO_CARDS] = { 0, };
static int irq[MAX_EEPRO_CARDS] = { 0, };
static int mem[MAX_EEPRO_CARDS] = { 0, };

Somehow, I get the feeling that passing on the I/O address and
Interrupt at modules initialisation time did not work correctly.

Greetings,

Frank Breure.

--
Todays saying:
     Don't use a big word where a diminutive one will suffice.

PS: Here's the patch:

--Multipart_Tue_Dec__3_11:02:22_1996-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="eepro.diff" Content-Transfer-Encoding: 7bit

--- linux/drivers/net/eepro.c~ Mon Oct 7 05:55:46 1996 +++ linux/drivers/net/eepro.c Tue Dec 3 10:41:14 1996 @@ -1252,39 +1252,65 @@ } #ifdef MODULE -static char devicename[9] = { 0, }; -static struct device dev_eepro = { - devicename, /* device name is inserted by linux/drivers/net/net_init.c */ - 0, 0, 0, 0, - 0, 0, - 0, 0, 0, NULL, eepro_probe }; - -static int io = 0x200; -static int irq = 0; -static int mem = (RCV_RAM/1024); /* Size of the rx buffer in KB */ + +#define MAX_EEPRO_CARDS 4 /* Max number of NE cards per module */ +#define NAMELEN 8 /* # of chars for storing dev->name */ +static char namelist[NAMELEN * MAX_EEPRO_CARDS] = { 0, }; +static struct device dev_eepro[MAX_EEPRO_CARDS] = { + { + NULL, /* assign a chunk of namelist[] below */ + 0, 0, 0, 0, + 0, 0, + 0, 0, 0, NULL, NULL + }, +}; + +static int io[MAX_EEPRO_CARDS] = { 0, }; +static int irq[MAX_EEPRO_CARDS] = { 0, }; +static int mem[MAX_EEPRO_CARDS] = { 0, }; int init_module(void) { - if (io == 0) - printk("eepro: You should not use auto-probing with insmod!\n"); - dev_eepro.base_addr = io; - dev_eepro.irq = irq; - dev_eepro.mem_end = mem; + int this_dev, found = 0; - if (register_netdev(&dev_eepro) != 0) - return -EIO; + for (this_dev = 0; this_dev < MAX_EEPRO_CARDS; this_dev++) { + struct device *dev = &dev_eepro[this_dev]; + dev->name = namelist+(NAMELEN*this_dev); + dev->irq = irq[this_dev]; + dev->base_addr = io[this_dev]; + dev->mem_end = mem[this_dev]; + dev->init = eepro_probe; + if (io[this_dev] == 0) { + if (this_dev != 0) break; /* only complain once */ + printk("eepro: WARNING! Module load-time probing does not always work!!\n"); + } + if (register_netdev(dev) != 0) { + printk(KERN_WARNING "eepro.c: No eepro card found (i/o = 0x%x).\n", io[this_dev]); + if (found != 0) return 0; /* Got at least one. */ + return -ENXIO; + } + found++; + } return 0; } void cleanup_module(void) { - unregister_netdev(&dev_eepro); - kfree_s(dev_eepro.priv,sizeof(struct eepro_local)); - dev_eepro.priv=NULL; + int this_dev; - /* If we don't do this, we can't re-insmod it later. */ - release_region(dev_eepro.base_addr, EEPRO_IO_EXTENT); + for (this_dev = 0; this_dev < MAX_EEPRO_CARDS; this_dev++) { + struct device *dev = &dev_eepro[this_dev]; + if (dev->priv != NULL) { + unregister_netdev(dev); + kfree_s(dev->priv,sizeof(struct eepro_local)); + dev->priv = NULL; + free_irq(dev->irq, NULL); + irq2dev_map[dev->irq] = NULL; + release_region(dev->base_addr, EEPRO_IO_EXTENT); + } + } } + #endif /* MODULE */

--Multipart_Tue_Dec__3_11:02:22_1996-1--