diff options
Diffstat (limited to 'drivers/net/ne.c')
-rw-r--r-- | drivers/net/ne.c | 272 |
1 files changed, 164 insertions, 108 deletions
diff --git a/drivers/net/ne.c b/drivers/net/ne.c index 79599900c4b5..eb681c0d51ba 100644 --- a/drivers/net/ne.c +++ b/drivers/net/ne.c | |||
@@ -64,6 +64,25 @@ static const char version2[] = | |||
64 | 64 | ||
65 | /* Do we support clones that don't adhere to 14,15 of the SAprom ? */ | 65 | /* Do we support clones that don't adhere to 14,15 of the SAprom ? */ |
66 | #define SUPPORT_NE_BAD_CLONES | 66 | #define SUPPORT_NE_BAD_CLONES |
67 | /* 0xbad = bad sig or no reset ack */ | ||
68 | #define BAD 0xbad | ||
69 | |||
70 | #define MAX_NE_CARDS 4 /* Max number of NE cards per module */ | ||
71 | static struct platform_device *pdev_ne[MAX_NE_CARDS]; | ||
72 | static int io[MAX_NE_CARDS]; | ||
73 | static int irq[MAX_NE_CARDS]; | ||
74 | static int bad[MAX_NE_CARDS]; | ||
75 | |||
76 | #ifdef MODULE | ||
77 | module_param_array(io, int, NULL, 0); | ||
78 | module_param_array(irq, int, NULL, 0); | ||
79 | module_param_array(bad, int, NULL, 0); | ||
80 | MODULE_PARM_DESC(io, "I/O base address(es),required"); | ||
81 | MODULE_PARM_DESC(irq, "IRQ number(s)"); | ||
82 | MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures"); | ||
83 | MODULE_DESCRIPTION("NE1000/NE2000 ISA/PnP Ethernet driver"); | ||
84 | MODULE_LICENSE("GPL"); | ||
85 | #endif /* MODULE */ | ||
67 | 86 | ||
68 | /* Do we perform extra sanity checks on stuff ? */ | 87 | /* Do we perform extra sanity checks on stuff ? */ |
69 | /* #define NE_SANITY_CHECK */ | 88 | /* #define NE_SANITY_CHECK */ |
@@ -74,6 +93,10 @@ static const char version2[] = | |||
74 | /* Do we have a non std. amount of memory? (in units of 256 byte pages) */ | 93 | /* Do we have a non std. amount of memory? (in units of 256 byte pages) */ |
75 | /* #define PACKETBUF_MEMSIZE 0x40 */ | 94 | /* #define PACKETBUF_MEMSIZE 0x40 */ |
76 | 95 | ||
96 | /* This is set up so that no ISA autoprobe takes place. We can't guarantee | ||
97 | that the ne2k probe is the last 8390 based probe to take place (as it | ||
98 | is at boot) and so the probe will get confused by any other 8390 cards. | ||
99 | ISA device autoprobes on a running machine are not recommended anyway. */ | ||
77 | #if !defined(MODULE) && (defined(CONFIG_ISA) || defined(CONFIG_M32R)) | 100 | #if !defined(MODULE) && (defined(CONFIG_ISA) || defined(CONFIG_M32R)) |
78 | /* Do we need a portlist for the ISA auto-probe ? */ | 101 | /* Do we need a portlist for the ISA auto-probe ? */ |
79 | #define NEEDS_PORTLIST | 102 | #define NEEDS_PORTLIST |
@@ -192,8 +215,13 @@ static int __init do_ne_probe(struct net_device *dev) | |||
192 | #endif | 215 | #endif |
193 | 216 | ||
194 | /* First check any supplied i/o locations. User knows best. <cough> */ | 217 | /* First check any supplied i/o locations. User knows best. <cough> */ |
195 | if (base_addr > 0x1ff) /* Check a single specified location. */ | 218 | if (base_addr > 0x1ff) { /* Check a single specified location. */ |
196 | return ne_probe1(dev, base_addr); | 219 | int ret = ne_probe1(dev, base_addr); |
220 | if (ret) | ||
221 | printk(KERN_WARNING "ne.c: No NE*000 card found at " | ||
222 | "i/o = %#lx\n", base_addr); | ||
223 | return ret; | ||
224 | } | ||
197 | else if (base_addr != 0) /* Don't probe at all. */ | 225 | else if (base_addr != 0) /* Don't probe at all. */ |
198 | return -ENXIO; | 226 | return -ENXIO; |
199 | 227 | ||
@@ -214,28 +242,6 @@ static int __init do_ne_probe(struct net_device *dev) | |||
214 | return -ENODEV; | 242 | return -ENODEV; |
215 | } | 243 | } |
216 | 244 | ||
217 | #ifndef MODULE | ||
218 | struct net_device * __init ne_probe(int unit) | ||
219 | { | ||
220 | struct net_device *dev = alloc_eip_netdev(); | ||
221 | int err; | ||
222 | |||
223 | if (!dev) | ||
224 | return ERR_PTR(-ENOMEM); | ||
225 | |||
226 | sprintf(dev->name, "eth%d", unit); | ||
227 | netdev_boot_setup_check(dev); | ||
228 | |||
229 | err = do_ne_probe(dev); | ||
230 | if (err) | ||
231 | goto out; | ||
232 | return dev; | ||
233 | out: | ||
234 | free_netdev(dev); | ||
235 | return ERR_PTR(err); | ||
236 | } | ||
237 | #endif | ||
238 | |||
239 | static int __init ne_probe_isapnp(struct net_device *dev) | 245 | static int __init ne_probe_isapnp(struct net_device *dev) |
240 | { | 246 | { |
241 | int i; | 247 | int i; |
@@ -329,7 +335,7 @@ static int __init ne_probe1(struct net_device *dev, unsigned long ioaddr) | |||
329 | with an otherwise unused dev->mem_end value of "0xBAD" will | 335 | with an otherwise unused dev->mem_end value of "0xBAD" will |
330 | cause the driver to skip these parts of the probe. */ | 336 | cause the driver to skip these parts of the probe. */ |
331 | 337 | ||
332 | bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad)); | 338 | bad_card = ((dev->base_addr != 0) && (dev->mem_end == BAD)); |
333 | 339 | ||
334 | /* Reset card. Who knows what dain-bramaged state it was left in. */ | 340 | /* Reset card. Who knows what dain-bramaged state it was left in. */ |
335 | 341 | ||
@@ -806,39 +812,84 @@ retry: | |||
806 | static int __init ne_drv_probe(struct platform_device *pdev) | 812 | static int __init ne_drv_probe(struct platform_device *pdev) |
807 | { | 813 | { |
808 | struct net_device *dev; | 814 | struct net_device *dev; |
815 | int err, this_dev = pdev->id; | ||
809 | struct resource *res; | 816 | struct resource *res; |
810 | int err, irq; | ||
811 | |||
812 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
813 | irq = platform_get_irq(pdev, 0); | ||
814 | if (!res || irq < 0) | ||
815 | return -ENODEV; | ||
816 | 817 | ||
817 | dev = alloc_eip_netdev(); | 818 | dev = alloc_eip_netdev(); |
818 | if (!dev) | 819 | if (!dev) |
819 | return -ENOMEM; | 820 | return -ENOMEM; |
820 | dev->irq = irq; | 821 | |
821 | dev->base_addr = res->start; | 822 | /* ne.c doesn't populate resources in platform_device, but |
823 | * rbtx4927_ne_init and rbtx4938_ne_init do register devices | ||
824 | * with resources. | ||
825 | */ | ||
826 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
827 | if (res) { | ||
828 | dev->base_addr = res->start; | ||
829 | dev->irq = platform_get_irq(pdev, 0); | ||
830 | } else { | ||
831 | if (this_dev < 0 || this_dev >= MAX_NE_CARDS) | ||
832 | return -EINVAL; | ||
833 | dev->base_addr = io[this_dev]; | ||
834 | dev->irq = irq[this_dev]; | ||
835 | dev->mem_end = bad[this_dev]; | ||
836 | } | ||
822 | err = do_ne_probe(dev); | 837 | err = do_ne_probe(dev); |
823 | if (err) { | 838 | if (err) { |
824 | free_netdev(dev); | 839 | free_netdev(dev); |
825 | return err; | 840 | return err; |
826 | } | 841 | } |
827 | platform_set_drvdata(pdev, dev); | 842 | platform_set_drvdata(pdev, dev); |
843 | |||
844 | /* Update with any values found by probing, don't update if | ||
845 | * resources were specified. | ||
846 | */ | ||
847 | if (!res) { | ||
848 | io[this_dev] = dev->base_addr; | ||
849 | irq[this_dev] = dev->irq; | ||
850 | } | ||
828 | return 0; | 851 | return 0; |
829 | } | 852 | } |
830 | 853 | ||
831 | static int __exit ne_drv_remove(struct platform_device *pdev) | 854 | static int ne_drv_remove(struct platform_device *pdev) |
832 | { | 855 | { |
833 | struct net_device *dev = platform_get_drvdata(pdev); | 856 | struct net_device *dev = platform_get_drvdata(pdev); |
834 | 857 | ||
835 | unregister_netdev(dev); | 858 | if (dev) { |
836 | free_irq(dev->irq, dev); | 859 | struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv; |
837 | release_region(dev->base_addr, NE_IO_EXTENT); | 860 | netif_device_detach(dev); |
838 | free_netdev(dev); | 861 | unregister_netdev(dev); |
862 | if (idev) | ||
863 | pnp_device_detach(idev); | ||
864 | /* Careful ne_drv_remove can be called twice, once from | ||
865 | * the platform_driver.remove and again when the | ||
866 | * platform_device is being removed. | ||
867 | */ | ||
868 | ei_status.priv = 0; | ||
869 | free_irq(dev->irq, dev); | ||
870 | release_region(dev->base_addr, NE_IO_EXTENT); | ||
871 | free_netdev(dev); | ||
872 | platform_set_drvdata(pdev, NULL); | ||
873 | } | ||
839 | return 0; | 874 | return 0; |
840 | } | 875 | } |
841 | 876 | ||
877 | /* Remove unused devices or all if true. */ | ||
878 | static void ne_loop_rm_unreg(int all) | ||
879 | { | ||
880 | int this_dev; | ||
881 | struct platform_device *pdev; | ||
882 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | ||
883 | pdev = pdev_ne[this_dev]; | ||
884 | /* No network device == unused */ | ||
885 | if (pdev && (!platform_get_drvdata(pdev) || all)) { | ||
886 | ne_drv_remove(pdev); | ||
887 | platform_device_unregister(pdev); | ||
888 | pdev_ne[this_dev] = NULL; | ||
889 | } | ||
890 | } | ||
891 | } | ||
892 | |||
842 | #ifdef CONFIG_PM | 893 | #ifdef CONFIG_PM |
843 | static int ne_drv_suspend(struct platform_device *pdev, pm_message_t state) | 894 | static int ne_drv_suspend(struct platform_device *pdev, pm_message_t state) |
844 | { | 895 | { |
@@ -873,7 +924,7 @@ static int ne_drv_resume(struct platform_device *pdev) | |||
873 | #endif | 924 | #endif |
874 | 925 | ||
875 | static struct platform_driver ne_driver = { | 926 | static struct platform_driver ne_driver = { |
876 | .remove = __exit_p(ne_drv_remove), | 927 | .remove = ne_drv_remove, |
877 | .suspend = ne_drv_suspend, | 928 | .suspend = ne_drv_suspend, |
878 | .resume = ne_drv_resume, | 929 | .resume = ne_drv_resume, |
879 | .driver = { | 930 | .driver = { |
@@ -882,91 +933,96 @@ static struct platform_driver ne_driver = { | |||
882 | }, | 933 | }, |
883 | }; | 934 | }; |
884 | 935 | ||
885 | static int __init ne_init(void) | 936 | static void __init ne_add_devices(void) |
886 | { | 937 | { |
887 | return platform_driver_probe(&ne_driver, ne_drv_probe); | 938 | int this_dev; |
888 | } | 939 | struct platform_device *pdev; |
889 | 940 | ||
890 | static void __exit ne_exit(void) | 941 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { |
891 | { | 942 | if (pdev_ne[this_dev]) |
892 | platform_driver_unregister(&ne_driver); | 943 | continue; |
944 | pdev = platform_device_register_simple( | ||
945 | DRV_NAME, this_dev, NULL, 0); | ||
946 | if (IS_ERR(pdev)) | ||
947 | continue; | ||
948 | pdev_ne[this_dev] = pdev; | ||
949 | } | ||
893 | } | 950 | } |
894 | 951 | ||
895 | #ifdef MODULE | 952 | #ifdef MODULE |
896 | #define MAX_NE_CARDS 4 /* Max number of NE cards per module */ | 953 | int __init init_module() |
897 | static struct net_device *dev_ne[MAX_NE_CARDS]; | ||
898 | static int io[MAX_NE_CARDS]; | ||
899 | static int irq[MAX_NE_CARDS]; | ||
900 | static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */ | ||
901 | |||
902 | module_param_array(io, int, NULL, 0); | ||
903 | module_param_array(irq, int, NULL, 0); | ||
904 | module_param_array(bad, int, NULL, 0); | ||
905 | MODULE_PARM_DESC(io, "I/O base address(es),required"); | ||
906 | MODULE_PARM_DESC(irq, "IRQ number(s)"); | ||
907 | MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures"); | ||
908 | MODULE_DESCRIPTION("NE1000/NE2000 ISA/PnP Ethernet driver"); | ||
909 | MODULE_LICENSE("GPL"); | ||
910 | |||
911 | /* This is set up so that no ISA autoprobe takes place. We can't guarantee | ||
912 | that the ne2k probe is the last 8390 based probe to take place (as it | ||
913 | is at boot) and so the probe will get confused by any other 8390 cards. | ||
914 | ISA device autoprobes on a running machine are not recommended anyway. */ | ||
915 | |||
916 | int __init init_module(void) | ||
917 | { | 954 | { |
918 | int this_dev, found = 0; | 955 | int retval; |
919 | int plat_found = !ne_init(); | 956 | ne_add_devices(); |
920 | 957 | retval = platform_driver_probe(&ne_driver, ne_drv_probe); | |
921 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 958 | if (retval) { |
922 | struct net_device *dev = alloc_eip_netdev(); | 959 | if (io[0] == 0) |
923 | if (!dev) | 960 | printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\"" |
924 | break; | 961 | " value(s) for ISA cards.\n"); |
925 | dev->irq = irq[this_dev]; | 962 | ne_loop_rm_unreg(1); |
926 | dev->mem_end = bad[this_dev]; | 963 | return retval; |
927 | dev->base_addr = io[this_dev]; | ||
928 | if (do_ne_probe(dev) == 0) { | ||
929 | dev_ne[found++] = dev; | ||
930 | continue; | ||
931 | } | ||
932 | free_netdev(dev); | ||
933 | if (found || plat_found) | ||
934 | break; | ||
935 | if (io[this_dev] != 0) | ||
936 | printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]); | ||
937 | else | ||
938 | printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n"); | ||
939 | return -ENXIO; | ||
940 | } | 964 | } |
941 | if (found || plat_found) | ||
942 | return 0; | ||
943 | return -ENODEV; | ||
944 | } | ||
945 | 965 | ||
946 | static void cleanup_card(struct net_device *dev) | 966 | /* Unregister unused platform_devices. */ |
967 | ne_loop_rm_unreg(0); | ||
968 | return retval; | ||
969 | } | ||
970 | #else /* MODULE */ | ||
971 | static int __init ne_init(void) | ||
947 | { | 972 | { |
948 | struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv; | 973 | int retval = platform_driver_probe(&ne_driver, ne_drv_probe); |
949 | if (idev) | 974 | |
950 | pnp_device_detach(idev); | 975 | /* Unregister unused platform_devices. */ |
951 | free_irq(dev->irq, dev); | 976 | ne_loop_rm_unreg(0); |
952 | release_region(dev->base_addr, NE_IO_EXTENT); | 977 | return retval; |
953 | } | 978 | } |
979 | module_init(ne_init); | ||
954 | 980 | ||
955 | void __exit cleanup_module(void) | 981 | struct net_device * __init ne_probe(int unit) |
956 | { | 982 | { |
957 | int this_dev; | 983 | int this_dev; |
984 | struct net_device *dev; | ||
985 | |||
986 | /* Find an empty slot, that is no net_device and zero io port. */ | ||
987 | this_dev = 0; | ||
988 | while ((pdev_ne[this_dev] && platform_get_drvdata(pdev_ne[this_dev])) || | ||
989 | io[this_dev]) { | ||
990 | if (++this_dev == MAX_NE_CARDS) | ||
991 | return ERR_PTR(-ENOMEM); | ||
992 | } | ||
993 | |||
994 | /* Get irq, io from kernel command line */ | ||
995 | dev = alloc_eip_netdev(); | ||
996 | if (!dev) | ||
997 | return ERR_PTR(-ENOMEM); | ||
958 | 998 | ||
959 | ne_exit(); | 999 | sprintf(dev->name, "eth%d", unit); |
1000 | netdev_boot_setup_check(dev); | ||
1001 | |||
1002 | io[this_dev] = dev->base_addr; | ||
1003 | irq[this_dev] = dev->irq; | ||
1004 | bad[this_dev] = dev->mem_end; | ||
1005 | |||
1006 | free_netdev(dev); | ||
1007 | |||
1008 | ne_add_devices(); | ||
1009 | |||
1010 | /* return the first device found */ | ||
960 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { | 1011 | for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { |
961 | struct net_device *dev = dev_ne[this_dev]; | 1012 | if (pdev_ne[this_dev]) { |
962 | if (dev) { | 1013 | dev = platform_get_drvdata(pdev_ne[this_dev]); |
963 | unregister_netdev(dev); | 1014 | if (dev) |
964 | cleanup_card(dev); | 1015 | return dev; |
965 | free_netdev(dev); | ||
966 | } | 1016 | } |
967 | } | 1017 | } |
1018 | |||
1019 | return ERR_PTR(-ENODEV); | ||
968 | } | 1020 | } |
969 | #else /* MODULE */ | ||
970 | module_init(ne_init); | ||
971 | module_exit(ne_exit); | ||
972 | #endif /* MODULE */ | 1021 | #endif /* MODULE */ |
1022 | |||
1023 | static void __exit ne_exit(void) | ||
1024 | { | ||
1025 | platform_driver_unregister(&ne_driver); | ||
1026 | ne_loop_rm_unreg(1); | ||
1027 | } | ||
1028 | module_exit(ne_exit); | ||