Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / net / lance.c
index a39f7a7..bb5ad47 100644 (file)
@@ -47,6 +47,7 @@ static const char version[] = "lance.c:v1.15ac 1999/11/13 dplatt@3do.com, becker
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/slab.h>
@@ -56,8 +57,8 @@ static const char version[] = "lance.c:v1.15ac 1999/11/13 dplatt@3do.com, becker
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/bitops.h>
 
-#include <asm/bitops.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 
@@ -297,7 +298,7 @@ enum {OLD_LANCE = 0, PCNET_ISA=1, PCNET_ISAP=2, PCNET_PCI=3, PCNET_VLB=4, PCNET_
 static unsigned char lance_need_isa_bounce_buffers = 1;
 
 static int lance_open(struct net_device *dev);
-static void lance_init_ring(struct net_device *dev, int mode);
+static void lance_init_ring(struct net_device *dev, gfp_t mode);
 static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev);
 static int lance_rx(struct net_device *dev);
 static irqreturn_t lance_interrupt(int irq, void *dev_id, struct pt_regs *regs);
@@ -308,17 +309,6 @@ static void lance_tx_timeout (struct net_device *dev);
 
 \f
 
-static void cleanup_card(struct net_device *dev)
-{
-       struct lance_private *lp = dev->priv;
-       if (dev->dma != 4)
-               free_dma(dev->dma);
-       release_region(dev->base_addr, LANCE_TOTAL_SIZE);
-       kfree(lp->tx_bounce_buffs);
-       kfree((void*)lp->rx_buffs);
-       kfree(lp);
-}
-
 #ifdef MODULE
 #define MAX_CARDS              8       /* Max number of interfaces (cards) per module */
 
@@ -327,10 +317,10 @@ static int io[MAX_CARDS];
 static int dma[MAX_CARDS];
 static int irq[MAX_CARDS];
 
-MODULE_PARM(io, "1-" __MODULE_STRING(MAX_CARDS) "i");
-MODULE_PARM(dma, "1-" __MODULE_STRING(MAX_CARDS) "i");
-MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_CARDS) "i");
-MODULE_PARM(lance_debug, "i");
+module_param_array(io, int, NULL, 0);
+module_param_array(dma, int, NULL, 0);
+module_param_array(irq, int, NULL, 0);
+module_param(lance_debug, int, 0);
 MODULE_PARM_DESC(io, "LANCE/PCnet I/O base address(es),required");
 MODULE_PARM_DESC(dma, "LANCE/PCnet ISA DMA channel (ignored for some devices)");
 MODULE_PARM_DESC(irq, "LANCE/PCnet IRQ number (ignored for some devices)");
@@ -355,11 +345,8 @@ int init_module(void)
                dev->base_addr = io[this_dev];
                dev->dma = dma[this_dev];
                if (do_lance_probe(dev) == 0) {
-                       if (register_netdev(dev) == 0) {
-                               dev_lance[found++] = dev;
-                               continue;
-                       }
-                       cleanup_card(dev);
+                       dev_lance[found++] = dev;
+                       continue;
                }
                free_netdev(dev);
                break;
@@ -369,6 +356,17 @@ int init_module(void)
        return -ENXIO;
 }
 
+static void cleanup_card(struct net_device *dev)
+{
+       struct lance_private *lp = dev->priv;
+       if (dev->dma != 4)
+               free_dma(dev->dma);
+       release_region(dev->base_addr, LANCE_TOTAL_SIZE);
+       kfree(lp->tx_bounce_buffs);
+       kfree((void*)lp->rx_buffs);
+       kfree(lp);
+}
+
 void cleanup_module(void)
 {
        int this_dev;
@@ -432,6 +430,7 @@ static int __init do_lance_probe(struct net_device *dev)
        return -ENODEV;
 }
 
+#ifndef MODULE
 struct net_device * __init lance_probe(int unit)
 {
        struct net_device *dev = alloc_etherdev(0);
@@ -446,16 +445,12 @@ struct net_device * __init lance_probe(int unit)
        err = do_lance_probe(dev);
        if (err)
                goto out;
-       err = register_netdev(dev);
-       if (err)
-               goto out1;
        return dev;
-out1:
-       cleanup_card(dev);
 out:
        free_netdev(dev);
        return ERR_PTR(err);
 }
+#endif
 
 static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int options)
 {
@@ -469,20 +464,25 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
        static int did_version;                 /* Already printed version info. */
        unsigned long flags;
        int err = -ENOMEM;
+       void __iomem *bios;
 
        /* First we look for special cases.
           Check for HP's on-board ethernet by looking for 'HP' in the BIOS.
           There are two HP versions, check the BIOS for the configuration port.
           This method provided by L. Julliard, Laurent_Julliard@grenoble.hp.com.
           */
-       if (isa_readw(0x000f0102) == 0x5048)  {
+       bios = ioremap(0xf00f0, 0x14);
+       if (!bios)
+               return -ENOMEM;
+       if (readw(bios + 0x12) == 0x5048)  {
                static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360};
-               int hp_port = (isa_readl(0x000f00f1) & 1)  ? 0x499 : 0x99;
+               int hp_port = (readl(bios + 1) & 1)  ? 0x499 : 0x99;
                /* We can have boards other than the built-in!  Verify this is on-board. */
                if ((inb(hp_port) & 0xc0) == 0x80
                        && ioaddr_table[inb(hp_port) & 3] == ioaddr)
                        hp_builtin = hp_port;
        }
+       iounmap(bios);
        /* We also recognize the HP Vectra on-board here, but check below. */
        hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00
                                && inb(ioaddr+2) == 0x09);
@@ -721,6 +721,9 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
        dev->tx_timeout = lance_tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
 
+       err = register_netdev(dev);
+       if (err)
+               goto out_dma;
        return 0;
 out_dma:
        if (dev->dma != 4)
@@ -832,7 +835,7 @@ lance_purge_ring(struct net_device *dev)
        /* Free all the skbuffs in the Rx and Tx queues. */
        for (i = 0; i < RX_RING_SIZE; i++) {
                struct sk_buff *skb = lp->rx_skbuff[i];
-               lp->rx_skbuff[i] = 0;
+               lp->rx_skbuff[i] = NULL;
                lp->rx_ring[i].base = 0;                /* Not owned by LANCE chip. */
                if (skb)
                        dev_kfree_skb_any(skb);
@@ -848,7 +851,7 @@ lance_purge_ring(struct net_device *dev)
 
 /* Initialize the LANCE Rx and Tx rings. */
 static void
-lance_init_ring(struct net_device *dev, int gfp)
+lance_init_ring(struct net_device *dev, gfp_t gfp)
 {
        struct lance_private *lp = dev->priv;
        int i;
@@ -864,7 +867,7 @@ lance_init_ring(struct net_device *dev, int gfp)
                lp->rx_skbuff[i] = skb;
                if (skb) {
                        skb->dev = dev;
-                       rx_buff = skb->tail;
+                       rx_buff = skb->data;
                } else
                        rx_buff = kmalloc(PKT_BUF_SZ, GFP_DMA | gfp);
                if (rx_buff == NULL)
@@ -876,7 +879,7 @@ lance_init_ring(struct net_device *dev, int gfp)
        /* The Tx buffer address is filled in as needed, but we do need to clear
           the upper ownership bit. */
        for (i = 0; i < TX_RING_SIZE; i++) {
-               lp->tx_skbuff[i] = 0;
+               lp->tx_skbuff[i] = NULL;
                lp->tx_ring[i].base = 0;
        }
 
@@ -1081,7 +1084,7 @@ lance_interrupt(int irq, void *dev_id, struct pt_regs * regs)
                                   in the bounce buffer. */
                                if (lp->tx_skbuff[entry]) {
                                        dev_kfree_skb_irq(lp->tx_skbuff[entry]);
-                                       lp->tx_skbuff[entry] = 0;
+                                       lp->tx_skbuff[entry] = NULL;
                                }
                                dirty_tx++;
                        }