[parisc-linux-cvs] -pa53, fix lasi_82596 module problems, allow up to four 82596 devices

Helge Deller deller@gmx.de
Sat, 13 Oct 2001 13:42:15 +0200


Index: Makefile
===================================================================
RCS file: /home/cvs/parisc/linux/Makefile,v
retrieving revision 1.164
diff -u -p -r1.164 Makefile
--- Makefile	2001/10/13 03:56:22	1.164
+++ Makefile	2001/10/13 11:34:57
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 9
-EXTRAVERSION = -pa52
+EXTRAVERSION = -pa53
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
Index: lasi_82596.c
===================================================================
RCS file: /home/cvs/parisc/linux/drivers/net/lasi_82596.c,v
retrieving revision 1.23
diff -u -p -r1.23 lasi_82596.c
--- lasi_82596.c	2001/10/03 02:43:57	1.23
+++ lasi_82596.c	2001/10/13 11:35:20
@@ -98,7 +98,7 @@
 
 #include "../gsc/busdevice.h" /* XXX */
 
-static char version[] __initdata =
+static char version[] __devinitdata =
 	"82596.c $Revision: 1.23 $\n";
 
 /* DEBUG flags
@@ -123,7 +123,7 @@ static char version[] __initdata =
 #define DEB_ANY		0xffff
 
 
-#define DEB(x,y)	if (i596_debug & (x)) y
+#define DEB(x,y)	if (i596_debug & (x)) { y; }
 
 
 #define  CHECK_WBACK(addr,len) \
@@ -185,12 +185,15 @@ MODULE_AUTHOR("Richard Hirst");
 MODULE_DESCRIPTION("i82596 driver");
 MODULE_PARM(i596_debug, "i");
 MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
+EXPORT_NO_SYMBOLS;
 
 /* Copy frames shorter than rx_copybreak, otherwise pass on up in
  * a full sized sk_buff.  Value of 100 stolen from tulip.c (!alpha).
  */
 static int rx_copybreak = 100;
 
+#define MAX_DRIVERS	4	/* max count of drivers */
+
 #define PKT_BUF_SZ	1536
 #define MAX_MC_CNT	64
 
@@ -1134,7 +1137,7 @@ static void print_eth(unsigned char *add
 
 #define LAN_PROM_ADDR	0xF0810000
 
-static int __init i82596_probe(struct net_device *dev)
+static int __devinit i82596_probe(struct net_device *dev)
 {
 	int i;
 	struct i596_private *lp;
@@ -1178,7 +1181,7 @@ static int __init i82596_probe(struct ne
 		printk("82596.c: MAC of HP700 LAN read from EEPROM\n");
 	}
 
-	dev->mem_start = (int)pci_alloc_consistent(NULL, 
+	dev->mem_start = (unsigned long) pci_alloc_consistent(NULL, 
 		sizeof(struct i596_private), &dma_addr);
 	if (!dev->mem_start) {
 		printk("%s: Couldn't get consistent shared memory\n", dev->name);
@@ -1214,9 +1217,9 @@ static int __init i82596_probe(struct ne
 
 	lp = (struct i596_private *) dev->priv;
 	DEB(DEB_INIT,printk ("%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n",
-			dev->name, (unsigned long)lp,
-			sizeof(struct i596_private), (unsigned long)&lp->scb));
-	memset((void *) lp, 0, sizeof(struct i596_private));
+		dev->name, (unsigned long)lp,
+		sizeof(struct i596_private), (unsigned long)&lp->scb));
+	memset(lp, 0, sizeof(struct i596_private));
 
 	lp->scb.command = 0;
 	lp->scb.cmd = I596_NULL;
@@ -1497,13 +1500,21 @@ static void set_multicast_list(struct ne
 MODULE_PARM(debug, "i");
 MODULE_PARM_DESC(debug, "lasi_82596 debug mask");
 static int debug = -1;
+
+static int num_drivers;
+static struct net_device *netdevs[MAX_DRIVERS];
 
-static int __init
+static int __devinit
 lan_init_chip(struct parisc_device *dev)
 {
-	struct net_device *netdevice;
+	struct	net_device *netdevice;
 	int	retval, irq;
 
+	if (num_drivers >= MAX_DRIVERS) {
+		/* max count of possible i82596 drivers reached */
+		return -ENODEV;
+	}
+	
 	irq = busdevice_alloc_irq(dev); 
 
 	if (!irq) {
@@ -1531,6 +1542,8 @@ lan_init_chip(struct parisc_device *dev)
 		((struct i596_private *)netdevice->priv)->options = OPT_SWAP_PORT;
 	}
 
+	netdevs[num_drivers++] = netdevice;
+
 	return retval;
 }
 
@@ -1549,7 +1562,7 @@ static struct parisc_driver lan_driver =
 	probe:		lan_init_chip,
 };
 
-static int __init lasi_82596_init(void)
+static int __devinit lasi_82596_init(void)
 {
 	if (debug >= 0)
 		i596_debug = debug;
@@ -1558,21 +1571,31 @@ static int __init lasi_82596_init(void)
 
 module_init(lasi_82596_init);
 
-#if 0
 static void __exit lasi_82596_exit(void)
 {
-	unregister_netdev(&dev_82596);
-	lp = (struct i596_private *) dev_82596.priv;
+	int i;
 
-	if (dma_consistent)
-		pci_free_consistent( NULL, sizeof( struct i596_private), 
-			dev_82596.mem_start, lp->dma_addr);
-	else
-		free_page ((u32)(dev_82596.mem_start));
+	for (i=0; i<MAX_DRIVERS; i++) {
+		struct i596_private *lp;
+		struct net_device *netdevice;
+		
+		netdevice = netdevs[i];
+		if (!netdevice) 
+			continue;
+		
+		unregister_netdev(netdevice);
+
+		lp = (struct i596_private *) netdevice->priv;
+		if (dma_consistent)
+			pci_free_consistent( NULL, sizeof( struct i596_private), 
+				(void *)netdevice->mem_start, lp->dma_addr);
+		else
+			free_page(netdevice->mem_start);
 
-	dev_82596.priv = NULL;
+		netdevice->priv = NULL;
+	}
+
 	unregister_parisc_driver(&lan_driver);
 }
 
 module_exit(lasi_82596_exit);
-#endif