aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ne.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ne.c')
-rw-r--r--drivers/net/ne.c281
1 files changed, 172 insertions, 109 deletions
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index fa3ceca4e15c..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 */
71static struct platform_device *pdev_ne[MAX_NE_CARDS];
72static int io[MAX_NE_CARDS];
73static int irq[MAX_NE_CARDS];
74static int bad[MAX_NE_CARDS];
75
76#ifdef MODULE
77module_param_array(io, int, NULL, 0);
78module_param_array(irq, int, NULL, 0);
79module_param_array(bad, int, NULL, 0);
80MODULE_PARM_DESC(io, "I/O base address(es),required");
81MODULE_PARM_DESC(irq, "IRQ number(s)");
82MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures");
83MODULE_DESCRIPTION("NE1000/NE2000 ISA/PnP Ethernet driver");
84MODULE_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
97that the ne2k probe is the last 8390 based probe to take place (as it
98is at boot) and so the probe will get confused by any other 8390 cards.
99ISA 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
218struct 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;
233out:
234 free_netdev(dev);
235 return ERR_PTR(err);
236}
237#endif
238
239static int __init ne_probe_isapnp(struct net_device *dev) 245static 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,46 +812,95 @@ retry:
806static int __init ne_drv_probe(struct platform_device *pdev) 812static 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
831static int __exit ne_drv_remove(struct platform_device *pdev) 854static 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. */
878static 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
843static int ne_drv_suspend(struct platform_device *pdev, pm_message_t state) 894static int ne_drv_suspend(struct platform_device *pdev, pm_message_t state)
844{ 895{
845 struct net_device *dev = platform_get_drvdata(pdev); 896 struct net_device *dev = platform_get_drvdata(pdev);
846 897
847 if (netif_running(dev)) 898 if (netif_running(dev)) {
899 struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
848 netif_device_detach(dev); 900 netif_device_detach(dev);
901 if (idev)
902 pnp_stop_dev(idev);
903 }
849 return 0; 904 return 0;
850} 905}
851 906
@@ -854,6 +909,9 @@ static int ne_drv_resume(struct platform_device *pdev)
854 struct net_device *dev = platform_get_drvdata(pdev); 909 struct net_device *dev = platform_get_drvdata(pdev);
855 910
856 if (netif_running(dev)) { 911 if (netif_running(dev)) {
912 struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
913 if (idev)
914 pnp_start_dev(idev);
857 ne_reset_8390(dev); 915 ne_reset_8390(dev);
858 NS8390p_init(dev, 1); 916 NS8390p_init(dev, 1);
859 netif_device_attach(dev); 917 netif_device_attach(dev);
@@ -866,7 +924,7 @@ static int ne_drv_resume(struct platform_device *pdev)
866#endif 924#endif
867 925
868static struct platform_driver ne_driver = { 926static struct platform_driver ne_driver = {
869 .remove = __exit_p(ne_drv_remove), 927 .remove = ne_drv_remove,
870 .suspend = ne_drv_suspend, 928 .suspend = ne_drv_suspend,
871 .resume = ne_drv_resume, 929 .resume = ne_drv_resume,
872 .driver = { 930 .driver = {
@@ -875,91 +933,96 @@ static struct platform_driver ne_driver = {
875 }, 933 },
876}; 934};
877 935
878static int __init ne_init(void) 936static void __init ne_add_devices(void)
879{ 937{
880 return platform_driver_probe(&ne_driver, ne_drv_probe); 938 int this_dev;
881} 939 struct platform_device *pdev;
882 940
883static void __exit ne_exit(void) 941 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
884{ 942 if (pdev_ne[this_dev])
885 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 }
886} 950}
887 951
888#ifdef MODULE 952#ifdef MODULE
889#define MAX_NE_CARDS 4 /* Max number of NE cards per module */ 953int __init init_module()
890static struct net_device *dev_ne[MAX_NE_CARDS];
891static int io[MAX_NE_CARDS];
892static int irq[MAX_NE_CARDS];
893static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
894
895module_param_array(io, int, NULL, 0);
896module_param_array(irq, int, NULL, 0);
897module_param_array(bad, int, NULL, 0);
898MODULE_PARM_DESC(io, "I/O base address(es),required");
899MODULE_PARM_DESC(irq, "IRQ number(s)");
900MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures");
901MODULE_DESCRIPTION("NE1000/NE2000 ISA/PnP Ethernet driver");
902MODULE_LICENSE("GPL");
903
904/* This is set up so that no ISA autoprobe takes place. We can't guarantee
905that the ne2k probe is the last 8390 based probe to take place (as it
906is at boot) and so the probe will get confused by any other 8390 cards.
907ISA device autoprobes on a running machine are not recommended anyway. */
908
909int __init init_module(void)
910{ 954{
911 int this_dev, found = 0; 955 int retval;
912 int plat_found = !ne_init(); 956 ne_add_devices();
913 957 retval = platform_driver_probe(&ne_driver, ne_drv_probe);
914 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { 958 if (retval) {
915 struct net_device *dev = alloc_eip_netdev(); 959 if (io[0] == 0)
916 if (!dev) 960 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\""
917 break; 961 " value(s) for ISA cards.\n");
918 dev->irq = irq[this_dev]; 962 ne_loop_rm_unreg(1);
919 dev->mem_end = bad[this_dev]; 963 return retval;
920 dev->base_addr = io[this_dev];
921 if (do_ne_probe(dev) == 0) {
922 dev_ne[found++] = dev;
923 continue;
924 }
925 free_netdev(dev);
926 if (found || plat_found)
927 break;
928 if (io[this_dev] != 0)
929 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]);
930 else
931 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
932 return -ENXIO;
933 } 964 }
934 if (found || plat_found)
935 return 0;
936 return -ENODEV;
937}
938 965
939static 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 */
971static int __init ne_init(void)
940{ 972{
941 struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv; 973 int retval = platform_driver_probe(&ne_driver, ne_drv_probe);
942 if (idev) 974
943 pnp_device_detach(idev); 975 /* Unregister unused platform_devices. */
944 free_irq(dev->irq, dev); 976 ne_loop_rm_unreg(0);
945 release_region(dev->base_addr, NE_IO_EXTENT); 977 return retval;
946} 978}
979module_init(ne_init);
947 980
948void __exit cleanup_module(void) 981struct net_device * __init ne_probe(int unit)
949{ 982{
950 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);
951 998
952 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 */
953 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { 1011 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
954 struct net_device *dev = dev_ne[this_dev]; 1012 if (pdev_ne[this_dev]) {
955 if (dev) { 1013 dev = platform_get_drvdata(pdev_ne[this_dev]);
956 unregister_netdev(dev); 1014 if (dev)
957 cleanup_card(dev); 1015 return dev;
958 free_netdev(dev);
959 } 1016 }
960 } 1017 }
1018
1019 return ERR_PTR(-ENODEV);
961} 1020}
962#else /* MODULE */
963module_init(ne_init);
964module_exit(ne_exit);
965#endif /* MODULE */ 1021#endif /* MODULE */
1022
1023static void __exit ne_exit(void)
1024{
1025 platform_driver_unregister(&ne_driver);
1026 ne_loop_rm_unreg(1);
1027}
1028module_exit(ne_exit);