This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / net / hplance.c
index 08703d6..965f949 100644 (file)
@@ -40,7 +40,9 @@
 
 /* Our private data structure */
 struct hplance_private {
-       struct lance_private lance;
+  struct lance_private lance;
+  unsigned int scode;
+  void *base;
 };
 
 /* function prototypes... This is easy because all the grot is in the
@@ -48,96 +50,89 @@ struct hplance_private {
  * plus board-specific init, open and close actions. 
  * Oh, and we need to tell the generic code how to read and write LANCE registers...
  */
-static int __devinit hplance_init_one(struct dio_dev *d,
-                               const struct dio_device_id *ent);
-static void __devinit hplance_init(struct net_device *dev, 
-                               struct dio_dev *d);
-static void __devexit hplance_remove_one(struct dio_dev *d);
+static void hplance_init(struct net_device *dev, int scode);
+static int hplance_open(struct net_device *dev);
+static int hplance_close(struct net_device *dev);
 static void hplance_writerap(void *priv, unsigned short value);
 static void hplance_writerdp(void *priv, unsigned short value);
 static unsigned short hplance_readrdp(void *priv);
-static int hplance_open(struct net_device *dev);
-static int hplance_close(struct net_device *dev);
 
-static struct dio_device_id hplance_dio_tbl[] = {
-       { DIO_ID_LAN },
-       { 0 }
-};
+#ifdef MODULE
+static struct hplance_private *root_hplance_dev;
+#endif
 
-static struct dio_driver hplance_driver = {
-       .name      = "hplance",
-       .id_table  = hplance_dio_tbl,
-       .probe     = hplance_init_one,
-       .remove    = __devexit_p(hplance_remove_one),
-};
+static void cleanup_card(struct net_device *dev)
+{
+        struct hplance_private *lp = netdev_priv(dev);
+       dio_unconfig_board(lp->scode);
+}
 
 /* Find all the HP Lance boards and initialise them... */
-static int __devinit hplance_init_one(struct dio_dev *d,
-                               const struct dio_device_id *ent)
+struct net_device * __init hplance_probe(int unit)
 {
        struct net_device *dev;
-       int err = -ENOMEM;
+
+        if (!MACH_IS_HP300)
+                return ERR_PTR(-ENODEV);
 
        dev = alloc_etherdev(sizeof(struct hplance_private));
        if (!dev)
-               goto out;
-
-       err = -EBUSY;
-       if (!request_mem_region(dio_resource_start(d),
-                               dio_resource_len(d), d->name))
-               goto out_free_netdev;
-
-       hplance_init(dev, d);
-       err = register_netdev(dev);
-       if (err)
-               goto out_release_mem_region;
-
-       dio_set_drvdata(d, dev);
-       return 0;
+               return ERR_PTR(-ENOMEM);
 
- out_release_mem_region:
-       release_mem_region(dio_resource_start(d), dio_resource_len(d));
- out_free_netdev:
-       free_netdev(dev);
- out:
-       return err;
-}
-
-static void __devexit hplance_remove_one(struct dio_dev *d)
-{
-       struct net_device *dev = dio_get_drvdata(d);
+       if (unit >= 0) {
+               sprintf(dev->name, "eth%d", unit);
+               netdev_boot_setup_check(dev);
+       }
 
-       unregister_netdev(dev);
-       release_mem_region(dio_resource_start(d), dio_resource_len(d));
+       SET_MODULE_OWNER(dev);
+        
+        /* Isn't DIO nice? */
+        for(;;)
+        {
+                int scode = dio_find(DIO_ID_LAN);
+                                
+                if (!scode)
+                        break;
+                
+               dio_config_board(scode);
+                hplance_init(dev, scode);
+               if (!register_netdev(dev)) {
+                       struct hplance_private *lp = netdev_priv(dev);
+                       lp->next_module = root_hplance_dev;
+                       root_hplance_dev = lp;
+                       return dev;
+               }
+               cleanup_card(dev);
+        }
        free_netdev(dev);
+       return ERR_PTR(-ENODEV);
 }
 
-/* Initialise a single lance board at the given DIO device */
-static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
+/* Initialise a single lance board at the given select code */
+static void __init hplance_init(struct net_device *dev, int scode)
 {
-        unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
+        const char *name = dio_scodetoname(scode);
+        void *va = dio_scodetoviraddr(scode);
         struct hplance_private *lp;
         int i;
         
-        printk(KERN_INFO "%s: %s; select code %d, addr", dev->name, d->name, d->scode);
+        printk("%s: %s; select code %d, addr", dev->name, name, scode);
 
         /* reset the board */
         out_8(va+DIO_IDOFF, 0xff);
         udelay(100);                              /* ariba! ariba! udelay! udelay! */
 
         /* Fill the dev fields */
-        dev->base_addr = va;
+        dev->base_addr = (unsigned long)va;
         dev->open = &hplance_open;
         dev->stop = &hplance_close;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-        dev->poll_controller = lance_poll;
-#endif
         dev->hard_start_xmit = &lance_start_xmit;
         dev->get_stats = &lance_get_stats;
         dev->set_multicast_list = &lance_set_multicast;
         dev->dma = 0;
         
-        for (i=0; i<6; i++) {
+        for (i=0; i<6; i++)
+        {
                 /* The NVRAM holds our ethernet address, one nibble per byte,
                  * at bytes NVRAMOFF+1,3,5,7,9...
                  */
@@ -147,12 +142,12 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
         }
         
         lp = netdev_priv(dev);
-        lp->lance.name = (char*)d->name;                /* discards const, shut up gcc */
-        lp->lance.base = va;
+        lp->lance.name = (char*)name;                   /* discards const, shut up gcc */
+        lp->lance.ll = (struct lance_regs *)(va + HPLANCE_REGOFF);
         lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
         lp->lance.lance_init_block = 0;                 /* LANCE addr of same RAM */
         lp->lance.busmaster_regval = LE_C3_BSWP;        /* we're bigendian */
-        lp->lance.irq = d->ipl;
+        lp->lance.irq = dio_scodetoipl(scode);
         lp->lance.writerap = hplance_writerap;
         lp->lance.writerdp = hplance_writerdp;
         lp->lance.readrdp = hplance_readrdp;
@@ -160,6 +155,8 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
         lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
         lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
         lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
+        lp->scode = scode;
+       lp->base = va;
        printk(", irq %d\n", lp->lance.irq);
 }
 
@@ -168,64 +165,78 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
  */
 static void hplance_writerap(void *priv, unsigned short value)
 {
-       struct lance_private *lp = (struct lance_private *)priv;
-       do {
-               out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
-       } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
+       struct hplance_private *lp = (struct hplance_private *)priv;
+        struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
+        do {
+                lp->lance.ll->rap = value;
+        } while ((hpregs->status & LE_ACK) == 0);
 }
 
 static void hplance_writerdp(void *priv, unsigned short value)
 {
-       struct lance_private *lp = (struct lance_private *)priv;
-       do {
-               out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
-       } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
+       struct hplance_private *lp = (struct hplance_private *)priv;
+        struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
+        do {
+                lp->lance.ll->rdp = value;
+        } while ((hpregs->status & LE_ACK) == 0);
 }
 
 static unsigned short hplance_readrdp(void *priv)
 {
-       struct lance_private *lp = (struct lance_private *)priv;
-       __u16 value;
-       do {
-               value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
-       } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
-       return value;
+        unsigned short val;
+       struct hplance_private *lp = (struct hplance_private *)priv;
+        struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
+        do {
+                val = lp->lance.ll->rdp;
+        } while ((hpregs->status & LE_ACK) == 0);
+        return val;
 }
 
 static int hplance_open(struct net_device *dev)
 {
         int status;
-        struct lance_private *lp = netdev_priv(dev);
+        struct hplance_private *lp = netdev_priv(dev);
+        struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
         
         status = lance_open(dev);                 /* call generic lance open code */
         if (status)
                 return status;
         /* enable interrupts at board level. */
-        out_8(lp->base + HPLANCE_STATUS, LE_IE);
+        out_8(&(hpregs->status), LE_IE);
 
         return 0;
 }
 
 static int hplance_close(struct net_device *dev)
 {
-        struct lance_private *lp = netdev_priv(dev);
-
-        out_8(lp->base + HPLANCE_STATUS, 0);   /* disable interrupts at boardlevel */
+        struct hplance_private *lp = netdev_priv(dev);
+        struct hplance_reg *hpregs = (struct hplance_reg *)lp->base;
+        out_8(&(hpregs->status), 8);              /* disable interrupts at boardlevel */
         lance_close(dev);
         return 0;
 }
 
-int __init hplance_init_module(void)
+#ifdef MODULE
+MODULE_LICENSE("GPL");
+int init_module(void)
 {
-       return dio_module_init(&hplance_driver);
+       int found = 0;
+       while (!IS_ERR(hplance_probe(-1)))
+               found++;
+       return found ? 0 : -ENODEV;
 }
 
-void __exit hplance_cleanup_module(void)
+void cleanup_module(void)
 {
-        dio_unregister_driver(&hplance_driver);
+        /* Walk the chain of devices, unregistering them */
+        struct hplance_private *lp;
+        while (root_hplance_dev) {
+                lp = root_hplance_dev->next_module;
+                unregister_netdev(root_lance_dev->dev);
+                cleanup_card(root_lance_dev->dev);
+                free_netdev(root_lance_dev->dev);
+                root_lance_dev = lp;
+        }
 }
 
-module_init(hplance_init_module);
-module_exit(hplance_cleanup_module);
-
-MODULE_LICENSE("GPL");
+#endif /* MODULE */