meth driver renovation

The meth ethernet driver for the SGI IP32 aka O2 is so far still an old
style driver which does not use the device driver model. This is now
causing issues with some udev based gadgetry in debian-stable. Fixed by
converting the meth driver to a platform device.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

--
Fixes since previous patch:

o Fixed typo in meth_exit_module()
Signed-off-by: Jeff Garzik <jeff@garzik.org>

authored by

Ralf Baechle and committed by
Jeff Garzik
e9712901 73815538

+66 -24
+1 -1
arch/mips/sgi-ip32/Makefile
··· 3 3 # under Linux. 4 4 # 5 5 6 - obj-y += ip32-berr.o ip32-irq.o ip32-setup.o ip32-reset.o \ 6 + obj-y += ip32-berr.o ip32-irq.o ip32-platform.o ip32-setup.o ip32-reset.o \ 7 7 crime.o ip32-memory.o
+20
arch/mips/sgi-ip32/ip32-platform.c
··· 1 + #include <linux/init.h> 2 + #include <linux/platform_device.h> 3 + 4 + static __init int meth_devinit(void) 5 + { 6 + struct platform_device *pd; 7 + int ret; 8 + 9 + pd = platform_device_alloc("meth", -1); 10 + if (!pd) 11 + return -ENOMEM; 12 + 13 + ret = platform_device_add(pd); 14 + if (ret) 15 + platform_device_put(pd); 16 + 17 + return ret; 18 + } 19 + 20 + device_initcall(meth_devinit);
+45 -23
drivers/net/meth.c
··· 8 8 * as published by the Free Software Foundation; either version 9 9 * 2 of the License, or (at your option) any later version. 10 10 */ 11 - #include <linux/module.h> 12 - #include <linux/init.h> 13 - 14 - #include <linux/kernel.h> /* printk() */ 15 11 #include <linux/delay.h> 12 + #include <linux/dma-mapping.h> 13 + #include <linux/init.h> 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_device.h> 16 17 #include <linux/slab.h> 17 - #include <linux/errno.h> /* error codes */ 18 - #include <linux/types.h> /* size_t */ 19 - #include <linux/interrupt.h> /* mark_bh */ 18 + #include <linux/errno.h> 19 + #include <linux/types.h> 20 + #include <linux/interrupt.h> 20 21 21 22 #include <linux/in.h> 22 23 #include <linux/in6.h> ··· 34 33 35 34 #include <asm/io.h> 36 35 #include <asm/scatterlist.h> 37 - #include <linux/dma-mapping.h> 38 36 39 37 #include "meth.h" 40 38 ··· 51 51 52 52 53 53 static const char *meth_str="SGI O2 Fast Ethernet"; 54 - MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>"); 55 - MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver"); 56 54 57 55 #define HAVE_TX_TIMEOUT 58 56 /* The maximum time waited (in jiffies) before assuming a Tx failed. (400ms) */ ··· 782 784 /* 783 785 * The init function. 784 786 */ 785 - static struct net_device *meth_init(void) 787 + static int __init meth_probe(struct platform_device *pdev) 786 788 { 787 789 struct net_device *dev; 788 790 struct meth_private *priv; 789 - int ret; 791 + int err; 790 792 791 793 dev = alloc_etherdev(sizeof(struct meth_private)); 792 794 if (!dev) 793 - return ERR_PTR(-ENOMEM); 795 + return -ENOMEM; 794 796 795 797 dev->open = meth_open; 796 798 dev->stop = meth_release; ··· 806 808 807 809 priv = netdev_priv(dev); 808 810 spin_lock_init(&priv->meth_lock); 811 + SET_NETDEV_DEV(dev, &pdev->dev); 809 812 810 - ret = register_netdev(dev); 811 - if (ret) { 813 + err = register_netdev(dev); 814 + if (err) { 812 815 free_netdev(dev); 813 - return ERR_PTR(ret); 816 + return err; 814 817 } 815 818 816 819 printk(KERN_INFO "%s: SGI MACE Ethernet rev. %d\n", ··· 819 820 return 0; 820 821 } 821 822 822 - static struct net_device *meth_dev; 823 + static int __exit meth_remove(struct platform_device *pdev) 824 + { 825 + struct net_device *dev = platform_get_drvdata(pdev); 826 + 827 + unregister_netdev(dev); 828 + free_netdev(dev); 829 + platform_set_drvdata(pdev, NULL); 830 + 831 + return 0; 832 + } 833 + 834 + static struct platform_driver meth_driver = { 835 + .probe = meth_probe, 836 + .remove = __devexit_p(meth_remove), 837 + .driver = { 838 + .name = "meth", 839 + } 840 + }; 823 841 824 842 static int __init meth_init_module(void) 825 843 { 826 - meth_dev = meth_init(); 827 - if (IS_ERR(meth_dev)) 828 - return PTR_ERR(meth_dev); 829 - return 0; 844 + int err; 845 + 846 + err = platform_driver_register(&meth_driver); 847 + if (err) 848 + printk(KERN_ERR "Driver registration failed\n"); 849 + 850 + return err; 830 851 } 831 852 832 853 static void __exit meth_exit_module(void) 833 854 { 834 - unregister_netdev(meth_dev); 835 - free_netdev(meth_dev); 855 + platform_driver_unregister(&meth_driver); 836 856 } 837 857 838 858 module_init(meth_init_module); 839 859 module_exit(meth_exit_module); 860 + 861 + MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>"); 862 + MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver"); 863 + MODULE_LICENSE("GPL");