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 / depca.c
index 80e8617..0941d40 100644 (file)
 #include <linux/unistd.h>
 #include <linux/ctype.h>
 #include <linux/moduleparam.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/bitops.h>
 
 #include <asm/uaccess.h>
-#include <asm/bitops.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 
@@ -342,14 +342,15 @@ static char depca_string[] = "depca";
 static int depca_device_remove (struct device *device);
 
 #ifdef CONFIG_EISA
-struct eisa_device_id depca_eisa_ids[] = {
+static struct eisa_device_id depca_eisa_ids[] = {
        { "DEC4220", de422 },
        { "" }
 };
+MODULE_DEVICE_TABLE(eisa, depca_eisa_ids);
 
 static int depca_eisa_probe  (struct device *device);
 
-struct eisa_driver depca_eisa_driver = {
+static struct eisa_driver depca_eisa_driver = {
        .id_table = depca_eisa_ids,
        .driver   = {
                .name    = depca_string,
@@ -397,13 +398,19 @@ static struct mca_driver depca_mca_driver = {
 };
 #endif
 
-static int depca_isa_probe (struct device *);
+static int depca_isa_probe (struct platform_device *);
 
-static struct device_driver depca_isa_driver = {
-       .name   = depca_string,
-       .bus    = &platform_bus_type,
+static int __devexit depca_isa_remove(struct platform_device *pdev)
+{
+       return depca_device_remove(&pdev->dev);
+}
+
+static struct platform_driver depca_isa_driver = {
        .probe  = depca_isa_probe,
-       .remove = __devexit_p(depca_device_remove),
+       .remove = __devexit_p(depca_isa_remove),
+       .driver = {
+               .name   = depca_string,
+       },
 };
        
 /*
@@ -463,11 +470,11 @@ struct depca_private {
         } depca_bus;           /* type of bus */
        struct depca_init init_block;   /* Shadow Initialization block            */
 /* CPU address space fields */
-       struct depca_rx_desc *rx_ring;  /* Pointer to start of RX descriptor ring */
-       struct depca_tx_desc *tx_ring;  /* Pointer to start of TX descriptor ring */
-       void *rx_buff[NUM_RX_DESC];     /* CPU virt address of sh'd memory buffs  */
-       void *tx_buff[NUM_TX_DESC];     /* CPU virt address of sh'd memory buffs  */
-       void *sh_mem;           /* CPU mapped virt address of device RAM  */
+       struct depca_rx_desc __iomem *rx_ring;  /* Pointer to start of RX descriptor ring */
+       struct depca_tx_desc __iomem *tx_ring;  /* Pointer to start of TX descriptor ring */
+       void __iomem *rx_buff[NUM_RX_DESC];     /* CPU virt address of sh'd memory buffs  */
+       void __iomem *tx_buff[NUM_TX_DESC];     /* CPU virt address of sh'd memory buffs  */
+       void __iomem *sh_mem;   /* CPU mapped virt address of device RAM  */
        u_long mem_start;       /* Bus address of device RAM (before remap) */
        u_long mem_len;         /* device memory size */
 /* Device address space fields */
@@ -666,7 +673,7 @@ static int __init depca_hw_init (struct net_device *dev, struct device *device)
                outb(nicsr, DEPCA_NICSR);
        }
 
-       lp->lock = SPIN_LOCK_UNLOCKED;
+       spin_lock_init(&lp->lock);
        sprintf(lp->adapter_name, "%s (%s)",
                depca_signature[lp->adapter], device->bus_id);
        status = -EBUSY;
@@ -693,11 +700,11 @@ static int __init depca_hw_init (struct net_device *dev, struct device *device)
 
        /* Tx & Rx descriptors (aligned to a quadword boundary) */
        offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
-       lp->rx_ring = (struct depca_rx_desc *) (lp->sh_mem + offset);
+       lp->rx_ring = (struct depca_rx_desc __iomem *) (lp->sh_mem + offset);
        lp->rx_ring_offset = offset;
 
        offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
-       lp->tx_ring = (struct depca_tx_desc *) (lp->sh_mem + offset);
+       lp->tx_ring = (struct depca_tx_desc __iomem *) (lp->sh_mem + offset);
        lp->tx_ring_offset = offset;
 
        offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
@@ -1222,10 +1229,10 @@ static int InitRestartDepca(struct net_device *dev)
                /* clear IDON by writing a "1", enable interrupts and start lance */
                outw(IDON | INEA | STRT, DEPCA_DATA);
                if (depca_debug > 2) {
-                       printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, virt_to_phys(lp->sh_mem), inw(DEPCA_DATA));
+                       printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
                }
        } else {
-               printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, virt_to_phys(lp->sh_mem), inw(DEPCA_DATA));
+               printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
                status = -1;
        }
 
@@ -1405,7 +1412,7 @@ static int __init depca_mca_probe(struct device *device)
                irq = 11;
                break;
        default:
-               printk("%s: mca_probe IRQ error.  You should never get here (%d).\n", dev->name, where);
+               printk("%s: mca_probe IRQ error.  You should never get here (%d).\n", mdev->name, where);
                return -EINVAL;
        }
 
@@ -1469,15 +1476,6 @@ static int __init depca_mca_probe(struct device *device)
 ** ISA bus I/O device probe
 */
 
-static void depca_platform_release (struct device *device)
-{
-       struct platform_device *pldev;
-
-       /* free device */
-       pldev = to_platform_device (device);
-       kfree (pldev);
-}
-
 static void __init depca_platform_probe (void)
 {
        int i;
@@ -1490,19 +1488,16 @@ static void __init depca_platform_probe (void)
                 * line, use it (if valid) */
                if (io && io != depca_io_ports[i].iobase)
                        continue;
-               
-               if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL)))
+
+               pldev = platform_device_alloc(depca_string, i);
+               if (!pldev)
                        continue;
 
-               memset (pldev, 0, sizeof (*pldev));
-               pldev->name = depca_string;
-               pldev->id   = i;
                pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
-               pldev->dev.release       = depca_platform_release;
                depca_io_ports[i].device = pldev;
 
-               if (platform_device_register (pldev)) {
-                       kfree (pldev);
+               if (platform_device_add(pldev)) {
+                       platform_device_put(pldev);
                        depca_io_ports[i].device = NULL;
                        continue;
                }
@@ -1514,6 +1509,7 @@ static void __init depca_platform_probe (void)
                 * allocated structure */
                        
                        depca_io_ports[i].device = NULL;
+                       pldev->dev.platform_data = NULL;
                        platform_device_unregister (pldev);
                }
        }
@@ -1535,7 +1531,7 @@ static enum depca_type __init depca_shmem_probe (ulong *mem_start)
        return adapter;
 }
 
-static int __init depca_isa_probe (struct device *device)
+static int __init depca_isa_probe (struct platform_device *device)
 {
        struct net_device *dev;
        struct depca_private *lp;
@@ -1543,7 +1539,7 @@ static int __init depca_isa_probe (struct device *device)
        enum depca_type adapter = unknown;
        int status = 0;
 
-       ioaddr = (u_long) device->platform_data;
+       ioaddr = (u_long) device->dev.platform_data;
 
        if ((status = depca_common_init (ioaddr, &dev)))
                goto out;
@@ -1563,7 +1559,7 @@ static int __init depca_isa_probe (struct device *device)
        lp->adapter = adapter;
        lp->mem_start = mem_start;
        
-       if ((status = depca_hw_init(dev, device)))
+       if ((status = depca_hw_init(dev, &device->dev)))
                goto out_free;
        
        return 0;
@@ -1649,7 +1645,7 @@ static int __devexit depca_device_remove (struct device *device)
 static int __init DepcaSignature(char *name, u_long base_addr)
 {
        u_int i, j, k;
-       void *ptr;
+       void __iomem *ptr;
        char tmpstr[16];
        u_long prom_addr = base_addr + 0xc000;
        u_long mem_addr = base_addr + 0x8000; /* 32KB */
@@ -1826,7 +1822,7 @@ static int load_packet(struct net_device *dev, struct sk_buff *skb)
 
                /* set up the buffer descriptors */
                len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
-               for (i = entry; i != end; i = (++i) & lp->txRingMask) {
+               for (i = entry; i != end; i = (i+1) & lp->txRingMask) {
                        /* clean out flags */
                        writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
                        writew(0x0000, &lp->tx_ring[i].misc);   /* clears other error flags */
@@ -1876,17 +1872,17 @@ static void depca_dbg_open(struct net_device *dev)
                printk("Descriptor addresses (CPU):\nRX: ");
                for (i = 0; i < lp->rxRingMask; i++) {
                        if (i < 3) {
-                               printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
+                               printk("%p ", &lp->rx_ring[i].base);
                        }
                }
-               printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
+               printk("...%p\n", &lp->rx_ring[i].base);
                printk("TX: ");
                for (i = 0; i < lp->txRingMask; i++) {
                        if (i < 3) {
-                               printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
+                               printk("%p ", &lp->tx_ring[i].base);
                        }
                }
-               printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
+               printk("...%p\n", &lp->tx_ring[i].base);
                printk("\nDescriptor buffers (Device):\nRX: ");
                for (i = 0; i < lp->rxRingMask; i++) {
                        if (i < 3) {
@@ -1901,7 +1897,7 @@ static void depca_dbg_open(struct net_device *dev)
                        }
                }
                printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
-               printk("Initialisation block at 0x%8.8lx(Phys)\n", virt_to_phys(lp->sh_mem));
+               printk("Initialisation block at 0x%8.8lx(Phys)\n", lp->mem_start);
                printk("        mode: 0x%4.4x\n", p->mode);
                printk("        physical address: ");
                for (i = 0; i < ETH_ALEN - 1; i++) {
@@ -1915,7 +1911,7 @@ static void depca_dbg_open(struct net_device *dev)
                printk("%2.2x\n", p->mcast_table[i]);
                printk("        rx_ring at: 0x%8.8x\n", p->rx_ring);
                printk("        tx_ring at: 0x%8.8x\n", p->tx_ring);
-               printk("buffers (Phys): 0x%8.8lx\n", virt_to_phys(lp->sh_mem) + lp->buffs_offset);
+               printk("buffers (Phys): 0x%8.8lx\n", lp->mem_start + lp->buffs_offset);
                printk("Ring size:\nRX: %d  Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen);
                printk("TX: %d  Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen);
                outw(CSR2, DEPCA_ADDR);
@@ -1937,7 +1933,7 @@ static void depca_dbg_open(struct net_device *dev)
 static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct depca_private *lp = (struct depca_private *) dev->priv;
-       struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
+       struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_ifru;
        int i, status = 0;
        u_long ioaddr = dev->base_addr;
        union {
@@ -2092,7 +2088,7 @@ static int __init depca_module_init (void)
 #ifdef CONFIG_EISA
         err |= eisa_driver_register (&depca_eisa_driver);
 #endif
-       err |= driver_register (&depca_isa_driver);
+       err |= platform_driver_register (&depca_isa_driver);
        depca_platform_probe ();
        
         return err;
@@ -2107,10 +2103,11 @@ static void __exit depca_module_exit (void)
 #ifdef CONFIG_EISA
         eisa_driver_unregister (&depca_eisa_driver);
 #endif
-       driver_unregister (&depca_isa_driver);
+       platform_driver_unregister (&depca_isa_driver);
 
        for (i = 0; depca_io_ports[i].iobase; i++) {
                if (depca_io_ports[i].device) {
+                       depca_io_ports[i].device->dev.platform_data = NULL;
                        platform_device_unregister (depca_io_ports[i].device);
                        depca_io_ports[i].device = NULL;
                }