Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * INET     An implementation of the TCP/IP protocol suite for the LINUX
0004  *      operating system.  INET is implemented using the  BSD Socket
0005  *      interface as the means of communication with the user level.
0006  *
0007  *      Holds initial configuration information for devices.
0008  *
0009  * Version: @(#)Space.c 1.0.7   08/12/93
0010  *
0011  * Authors: Ross Biro
0012  *      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
0013  *      Donald J. Becker, <becker@scyld.com>
0014  *
0015  * Changelog:
0016  *      Stephen Hemminger (09/2003)
0017  *      - get rid of pre-linked dev list, dynamic device allocation
0018  *      Paul Gortmaker (03/2002)
0019  *      - struct init cleanup, enable multiple ISA autoprobes.
0020  *      Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 09/1999
0021  *      - fix sbni: s/device/net_device/
0022  *      Paul Gortmaker (06/98):
0023  *       - sort probes in a sane way, make sure all (safe) probes
0024  *         get run once & failed autoprobes don't autoprobe again.
0025  */
0026 #include <linux/netdevice.h>
0027 #include <linux/etherdevice.h>
0028 #include <linux/errno.h>
0029 #include <linux/init.h>
0030 #include <linux/netlink.h>
0031 #include <net/Space.h>
0032 
0033 /*
0034  * This structure holds boot-time configured netdevice settings. They
0035  * are then used in the device probing.
0036  */
0037 struct netdev_boot_setup {
0038     char name[IFNAMSIZ];
0039     struct ifmap map;
0040 };
0041 #define NETDEV_BOOT_SETUP_MAX 8
0042 
0043 
0044 /******************************************************************************
0045  *
0046  *            Device Boot-time Settings Routines
0047  *
0048  ******************************************************************************/
0049 
0050 /* Boot time configuration table */
0051 static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX];
0052 
0053 /**
0054  *  netdev_boot_setup_add   - add new setup entry
0055  *  @name: name of the device
0056  *  @map: configured settings for the device
0057  *
0058  *  Adds new setup entry to the dev_boot_setup list.  The function
0059  *  returns 0 on error and 1 on success.  This is a generic routine to
0060  *  all netdevices.
0061  */
0062 static int netdev_boot_setup_add(char *name, struct ifmap *map)
0063 {
0064     struct netdev_boot_setup *s;
0065     int i;
0066 
0067     s = dev_boot_setup;
0068     for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
0069         if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
0070             memset(s[i].name, 0, sizeof(s[i].name));
0071             strlcpy(s[i].name, name, IFNAMSIZ);
0072             memcpy(&s[i].map, map, sizeof(s[i].map));
0073             break;
0074         }
0075     }
0076 
0077     return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1;
0078 }
0079 
0080 /**
0081  * netdev_boot_setup_check  - check boot time settings
0082  * @dev: the netdevice
0083  *
0084  * Check boot time settings for the device.
0085  * The found settings are set for the device to be used
0086  * later in the device probing.
0087  * Returns 0 if no settings found, 1 if they are.
0088  */
0089 int netdev_boot_setup_check(struct net_device *dev)
0090 {
0091     struct netdev_boot_setup *s = dev_boot_setup;
0092     int i;
0093 
0094     for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
0095         if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
0096             !strcmp(dev->name, s[i].name)) {
0097             dev->irq = s[i].map.irq;
0098             dev->base_addr = s[i].map.base_addr;
0099             dev->mem_start = s[i].map.mem_start;
0100             dev->mem_end = s[i].map.mem_end;
0101             return 1;
0102         }
0103     }
0104     return 0;
0105 }
0106 EXPORT_SYMBOL(netdev_boot_setup_check);
0107 
0108 /**
0109  * netdev_boot_base - get address from boot time settings
0110  * @prefix: prefix for network device
0111  * @unit: id for network device
0112  *
0113  * Check boot time settings for the base address of device.
0114  * The found settings are set for the device to be used
0115  * later in the device probing.
0116  * Returns 0 if no settings found.
0117  */
0118 static unsigned long netdev_boot_base(const char *prefix, int unit)
0119 {
0120     const struct netdev_boot_setup *s = dev_boot_setup;
0121     char name[IFNAMSIZ];
0122     int i;
0123 
0124     sprintf(name, "%s%d", prefix, unit);
0125 
0126     /*
0127      * If device already registered then return base of 1
0128      * to indicate not to probe for this interface
0129      */
0130     if (__dev_get_by_name(&init_net, name))
0131         return 1;
0132 
0133     for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
0134         if (!strcmp(name, s[i].name))
0135             return s[i].map.base_addr;
0136     return 0;
0137 }
0138 
0139 /*
0140  * Saves at boot time configured settings for any netdevice.
0141  */
0142 static int __init netdev_boot_setup(char *str)
0143 {
0144     int ints[5];
0145     struct ifmap map;
0146 
0147     str = get_options(str, ARRAY_SIZE(ints), ints);
0148     if (!str || !*str)
0149         return 0;
0150 
0151     /* Save settings */
0152     memset(&map, 0, sizeof(map));
0153     if (ints[0] > 0)
0154         map.irq = ints[1];
0155     if (ints[0] > 1)
0156         map.base_addr = ints[2];
0157     if (ints[0] > 2)
0158         map.mem_start = ints[3];
0159     if (ints[0] > 3)
0160         map.mem_end = ints[4];
0161 
0162     /* Add new entry to the list */
0163     return netdev_boot_setup_add(str, &map);
0164 }
0165 
0166 __setup("netdev=", netdev_boot_setup);
0167 
0168 static int __init ether_boot_setup(char *str)
0169 {
0170     return netdev_boot_setup(str);
0171 }
0172 __setup("ether=", ether_boot_setup);
0173 
0174 
0175 /* A unified ethernet device probe.  This is the easiest way to have every
0176  * ethernet adaptor have the name "eth[0123...]".
0177  */
0178 
0179 struct devprobe2 {
0180     struct net_device *(*probe)(int unit);
0181     int status; /* non-zero if autoprobe has failed */
0182 };
0183 
0184 static int __init probe_list2(int unit, struct devprobe2 *p, int autoprobe)
0185 {
0186     struct net_device *dev;
0187 
0188     for (; p->probe; p++) {
0189         if (autoprobe && p->status)
0190             continue;
0191         dev = p->probe(unit);
0192         if (!IS_ERR(dev))
0193             return 0;
0194         if (autoprobe)
0195             p->status = PTR_ERR(dev);
0196     }
0197     return -ENODEV;
0198 }
0199 
0200 /* ISA probes that touch addresses < 0x400 (including those that also
0201  * look for EISA/PCI cards in addition to ISA cards).
0202  */
0203 static struct devprobe2 isa_probes[] __initdata = {
0204 #ifdef CONFIG_3C515
0205     {tc515_probe, 0},
0206 #endif
0207 #ifdef CONFIG_ULTRA
0208     {ultra_probe, 0},
0209 #endif
0210 #ifdef CONFIG_WD80x3
0211     {wd_probe, 0},
0212 #endif
0213 #if defined(CONFIG_NE2000) /* ISA (use ne2k-pci for PCI cards) */
0214     {ne_probe, 0},
0215 #endif
0216 #ifdef CONFIG_LANCE     /* ISA/VLB (use pcnet32 for PCI cards) */
0217     {lance_probe, 0},
0218 #endif
0219 #ifdef CONFIG_SMC9194
0220     {smc_init, 0},
0221 #endif
0222 #ifdef CONFIG_CS89x0_ISA
0223     {cs89x0_probe, 0},
0224 #endif
0225     {NULL, 0},
0226 };
0227 
0228 /* Unified ethernet device probe, segmented per architecture and
0229  * per bus interface. This drives the legacy devices only for now.
0230  */
0231 
0232 static void __init ethif_probe2(int unit)
0233 {
0234     unsigned long base_addr = netdev_boot_base("eth", unit);
0235 
0236     if (base_addr == 1)
0237         return;
0238 
0239     probe_list2(unit, isa_probes, base_addr == 0);
0240 }
0241 
0242 /*  Statically configured drivers -- order matters here. */
0243 static int __init net_olddevs_init(void)
0244 {
0245     int num;
0246 
0247     for (num = 0; num < 8; ++num)
0248         ethif_probe2(num);
0249 
0250 #ifdef CONFIG_COPS
0251     cops_probe(0);
0252     cops_probe(1);
0253     cops_probe(2);
0254 #endif
0255 
0256     return 0;
0257 }
0258 
0259 device_initcall(net_olddevs_init);