[parisc-linux-cvs] lasi_82596.c, minor tidy up plus request_mem_region

Richard Hirst rhirst@linuxcare.com
Tue, 3 Apr 2001 12:41:57 +0100


Tidy up probe and open error handling, make it register itself in
/dev/iomem, and remove the module stuff that was broken anyway.

Index: drivers/net/lasi_82596.c
===================================================================
RCS file: /home/cvs/parisc/linux/drivers/net/lasi_82596.c,v
retrieving revision 1.15
diff -u -r1.15 lasi_82596.c
--- lasi_82596.c        2001/01/25 00:01:15     1.15
+++ lasi_82596.c        2001/04/03 11:32:50
@@ -992,30 +992,33 @@
 
 static int i596_open(struct net_device *dev)
 {
-       int res = 0;
-
        DEB(DEB_OPEN,printk("%s: i596_open() irq %d.\n", dev->name, dev->irq));
 
+       MOD_INC_USE_COUNT;
+
        if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
                printk("%s: IRQ %d not free\n", dev->name, dev->irq);
-               return -EAGAIN;
+               goto out;
        }
 
-       request_region(dev->base_addr, 12, dev->name);
-
        init_rx_bufs(dev);
 
+       if (init_i596_mem(dev)) {
+               printk("%s: Failed to init memory\n", dev->name);
+               goto out_remove_rx_bufs;
+       }
+
        netif_start_queue(dev);
 
-       MOD_INC_USE_COUNT;
+       return 0;
 
-       /* Initialize the 82596 memory */
-       if (init_i596_mem(dev)) {
-               res = -EAGAIN;
-               free_irq(dev->irq, dev);
-       }
+out_remove_rx_bufs:
+       remove_rx_bufs(dev);
+       free_irq(dev->irq, dev);
+out:
+       MOD_DEC_USE_COUNT;
 
-       return res;
+       return -EAGAIN;
 }
 
 static void i596_tx_timeout (struct net_device *dev)
@@ -1160,6 +1163,12 @@
        if (!dev->base_addr || !dev->irq)
            return -ENODEV;
 
+       if (request_mem_region(dev->base_addr, I596_TOTAL_SIZE, "i82596") == NULL) {
+               printk("%s: iomem region (0x%lx/%x) is unavailable\n",
+                               dev->name, dev->base_addr, I596_TOTAL_SIZE);
+               return -ENODEV;
+       }
+
        if (!pdc_lan_station_id( (char*)&eth_addr, (void*)dev->base_addr)) {
            for(i=0;i<6;i++)
                eth_addr[i] = gsc_readb(LAN_PROM_ADDR+i);
@@ -1174,9 +1183,7 @@
                dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0);
                if (!dev->mem_start) {
                        printk("%s: Couldn't get shared memory\n", dev->name);
-#ifdef ENABLE_APRICOT
-                       release_region(dev->base_addr, I596_TOTAL_SIZE);
-#endif
+                       release_mem_region(dev->base_addr, I596_TOTAL_SIZE);
                        return -ENOMEM;
                }
                dma_addr = virt_to_bus(dev->mem_start);
@@ -1209,9 +1216,6 @@
                        sizeof(struct i596_private), (unsigned long)&lp->scb));
        memset((void *) lp, 0, sizeof(struct i596_private));
 
-#if 0
-       kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);
-#endif
        lp->options = options;
        lp->scb.command = 0;
        lp->scb.cmd = I596_NULL;
@@ -1420,7 +1424,7 @@
        free_irq(dev->irq, dev);
        remove_rx_bufs(dev);
 
-       release_region(dev->base_addr, 12);
+       release_mem_region(dev->base_addr, I596_TOTAL_SIZE);
 
        MOD_DEC_USE_COUNT;
 
@@ -1500,50 +1504,4 @@
                i596_add_cmd(dev, &cmd->cmd);
        }
 }
-
-#ifdef HAVE_DEVLIST
-static unsigned int i596_portlist[] __initdata =
-{0x300, 0};
-struct netdev_entry i596_drv =
-{"lasi_i82596", lasi_i82596_probe, I596_TOTAL_SIZE, i596_portlist};
-#endif
-
-#ifdef MODULE
-static char devicename[9] =
-{0,};
-static struct net_device dev_82596 =
-{
-       devicename,     /* device name inserted by drivers/net/net_init.c */
-       0, 0, 0, 0,
-       0, 0,           /* base, irq */
-       0, 0, 0, NULL, lasi_i82596_probe};
-
-
-MODULE_PARM(debug, "i");
-static int debug = -1;
-
-int init_module(void)
-{
-       if (debug >= 0)
-               i596_debug = debug;
-       if (register_netdev(&dev_82596) != 0)
-               return -EIO;
-       return 0;
-}
-
-void cleanup_module(void)
-{
-       unregister_netdev(&dev_82596);
-       lp = (struct i596_private *) dev_82596.priv;
-
-       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));
-
-       dev_82596.priv = NULL;
-}
-
-#endif                         /* MODULE */