From: Geert Uytterhoeven Ariadne Ethernet: Convert to the new driver model --- 25-akpm/drivers/net/ariadne.c | 188 +++++++++++++++++++++--------------------- 1 files changed, 97 insertions(+), 91 deletions(-) diff -puN drivers/net/ariadne.c~m68k-404 drivers/net/ariadne.c --- 25/drivers/net/ariadne.c~m68k-404 Fri Feb 20 15:10:35 2004 +++ 25-akpm/drivers/net/ariadne.c Fri Feb 20 15:10:35 2004 @@ -1,9 +1,8 @@ /* * Amiga Linux/m68k Ariadne Ethernet Driver * - * © Copyright 1995 by Geert Uytterhoeven (geert@linux-m68k.org) - * Peter De Schrijver - * (Peter.DeSchrijver@linux.cc.kuleuven.ac.be) + * © Copyright 1995-2003 by Geert Uytterhoeven (geert@linux-m68k.org) + * Peter De Schrijver (p2@mind.be) * * --------------------------------------------------------------------------- * @@ -101,8 +100,6 @@ struct ariadne_private { int dirty_tx; /* The ring entries to be free()ed. */ struct net_device_stats stats; char tx_full; - struct net_device *dev; /* Backpointer */ - struct ariadne_private *next_module; }; @@ -117,10 +114,6 @@ struct lancedata { u_short rx_buff[RX_RING_SIZE][PKT_BUF_SIZE/sizeof(u_short)]; }; -#ifdef MODULE -static struct ariadne_private *root_ariadne_dev; -#endif - static int ariadne_open(struct net_device *dev); static void ariadne_init_ring(struct net_device *dev); static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev); @@ -146,78 +139,89 @@ static void memcpyw(volatile u_short *de } -static int __init ariadne_probe(void) -{ - struct zorro_dev *z = NULL; - struct net_device *dev; - struct ariadne_private *priv; - int res = -ENODEV; +static int __devinit ariadne_init_one(struct zorro_dev *z, + const struct zorro_device_id *ent); +static void __devexit ariadne_remove_one(struct zorro_dev *z); - while ((z = zorro_find_device(ZORRO_PROD_VILLAGE_TRONIC_ARIADNE, z))) { - unsigned long board = z->resource.start; - unsigned long base_addr = board+ARIADNE_LANCE; - unsigned long mem_start = board+ARIADNE_RAM; - struct resource *r1, *r2; - - r1 = request_mem_region(base_addr, sizeof(struct Am79C960), - "Am79C960"); - if (!r1) continue; - r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM"); - if (!r2) { - release_resource(r1); - continue; - } - dev = alloc_etherdev(sizeof(struct ariadne_private)); +static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = { + { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE }, + { 0 } +}; - if (dev == NULL) { - release_resource(r1); - release_resource(r2); - return -ENOMEM; - } - SET_MODULE_OWNER(dev); - priv = dev->priv; +static struct zorro_driver ariadne_driver = { + .name = "ariadne", + .id_table = ariadne_zorro_tbl, + .probe = ariadne_init_one, + .remove = __devexit_p(ariadne_remove_one), +}; - r1->name = dev->name; - r2->name = dev->name; +static int __devinit ariadne_init_one(struct zorro_dev *z, + const struct zorro_device_id *ent) +{ + unsigned long board = z->resource.start; + unsigned long base_addr = board+ARIADNE_LANCE; + unsigned long mem_start = board+ARIADNE_RAM; + struct resource *r1, *r2; + struct net_device *dev; + struct ariadne_private *priv; + int err; - priv->dev = dev; - dev->dev_addr[0] = 0x00; - dev->dev_addr[1] = 0x60; - dev->dev_addr[2] = 0x30; - dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff; - dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff; - dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff; - printk("%s: Ariadne at 0x%08lx, Ethernet Address " - "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board, - dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], - dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); - - dev->base_addr = ZTWO_VADDR(base_addr); - dev->mem_start = ZTWO_VADDR(mem_start); - dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE; - - dev->open = &ariadne_open; - dev->stop = &ariadne_close; - dev->hard_start_xmit = &ariadne_start_xmit; - dev->tx_timeout = &ariadne_tx_timeout; - dev->watchdog_timeo = 5*HZ; - dev->get_stats = &ariadne_get_stats; - dev->set_multicast_list = &set_multicast_list; - - res = register_netdev(dev); - if (res) { - release_resource(r1); - release_resource(r2); - free_netdev(dev); - break; - } -#ifdef MODULE - priv->next_module = root_ariadne_dev; - root_ariadne_dev = priv; -#endif + r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960"); + if (!r1) + return -EBUSY; + r2 = request_mem_region(mem_start, ARIADNE_RAM_SIZE, "RAM"); + if (!r2) { + release_resource(r1); + return -EBUSY; + } + + dev = alloc_etherdev(sizeof(struct ariadne_private)); + if (dev == NULL) { + release_resource(r1); + release_resource(r2); + return -ENOMEM; + } + + SET_MODULE_OWNER(dev); + priv = dev->priv; + + r1->name = dev->name; + r2->name = dev->name; + + dev->dev_addr[0] = 0x00; + dev->dev_addr[1] = 0x60; + dev->dev_addr[2] = 0x30; + dev->dev_addr[3] = (z->rom.er_SerialNumber>>16) & 0xff; + dev->dev_addr[4] = (z->rom.er_SerialNumber>>8) & 0xff; + dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff; + printk("%s: Ariadne at 0x%08lx, Ethernet Address " + "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board, + dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], + dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); + + dev->base_addr = ZTWO_VADDR(base_addr); + dev->mem_start = ZTWO_VADDR(mem_start); + dev->mem_end = dev->mem_start+ARIADNE_RAM_SIZE; + + dev->open = &ariadne_open; + dev->stop = &ariadne_close; + dev->hard_start_xmit = &ariadne_start_xmit; + dev->tx_timeout = &ariadne_tx_timeout; + dev->watchdog_timeo = 5*HZ; + dev->get_stats = &ariadne_get_stats; + dev->set_multicast_list = &set_multicast_list; + + err = register_netdev(dev); + if (err) { + release_resource(r1); + release_resource(r2); + free_netdev(dev); + return err; } - return res; + zorro_set_drvdata(z, dev); + + return 0; } @@ -846,25 +850,27 @@ static void set_multicast_list(struct ne } -static void __exit ariadne_cleanup(void) +static void __devexit ariadne_remove_one(struct zorro_dev *z) { -#ifdef MODULE - struct ariadne_private *next; - struct net_device *dev; + struct net_device *dev = zorro_get_drvdata(z); - while (root_ariadne_dev) { - next = root_ariadne_dev->next_module; - dev = root_ariadne_dev->dev; - unregister_netdev(dev); - release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960)); - release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE); - free_netdev(dev); - root_ariadne_dev = next; - } -#endif + unregister_netdev(dev); + release_mem_region(ZTWO_PADDR(dev->base_addr), sizeof(struct Am79C960)); + release_mem_region(ZTWO_PADDR(dev->mem_start), ARIADNE_RAM_SIZE); + free_netdev(dev); +} + +static int __init ariadne_init_module(void) +{ + return zorro_module_init(&ariadne_driver); +} + +static void __exit ariadne_cleanup_module(void) +{ + zorro_unregister_driver(&ariadne_driver); } -module_init(ariadne_probe); -module_exit(ariadne_cleanup); +module_init(ariadne_init_module); +module_exit(ariadne_cleanup_module); MODULE_LICENSE("GPL"); _