linux-bk/drivers/net/Space.c
<<
>>
Prefs
   1/*
   2 * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3 *              operating system.  INET is implemented using the  BSD Socket
   4 *              interface as the means of communication with the user level.
   5 *
   6 *              Holds initial configuration information for devices.
   7 *
   8 * Version:     @(#)Space.c     1.0.7   08/12/93
   9 *
  10 * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11 *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12 *              Donald J. Becker, <becker@scyld.com>
  13 *
  14 * Changelog:
  15 *              Stephen Hemminger (09/2003)
  16 *              - get rid of pre-linked dev list, dynamic device allocation
  17 *              Paul Gortmaker (03/2002)
  18 *              - struct init cleanup, enable multiple ISA autoprobes.
  19 *              Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 09/1999
  20 *              - fix sbni: s/device/net_device/
  21 *              Paul Gortmaker (06/98): 
  22 *               - sort probes in a sane way, make sure all (safe) probes
  23 *                 get run once & failed autoprobes don't autoprobe again.
  24 *
  25 *              This program is free software; you can redistribute it and/or
  26 *              modify it under the terms of the GNU General Public License
  27 *              as published by the Free Software Foundation; either version
  28 *              2 of the License, or (at your option) any later version.
  29 */
  30#include <linux/config.h>
  31#include <linux/netdevice.h>
  32#include <linux/etherdevice.h>
  33#include <linux/trdevice.h>
  34#include <linux/errno.h>
  35#include <linux/init.h>
  36#include <linux/netlink.h>
  37#include <linux/divert.h>
  38
  39/* A unified ethernet device probe.  This is the easiest way to have every
  40   ethernet adaptor have the name "eth[0123...]".
  41   */
  42
  43extern int ne2_probe(struct net_device *dev);
  44extern int hp100_probe(struct net_device *dev);
  45extern int ultra_probe(struct net_device *dev);
  46extern int ultra32_probe(struct net_device *dev);
  47extern int wd_probe(struct net_device *dev);
  48extern int el2_probe(struct net_device *dev);
  49extern int ne_probe(struct net_device *dev);
  50extern int hp_probe(struct net_device *dev);
  51extern int hp_plus_probe(struct net_device *dev);
  52extern int express_probe(struct net_device *);
  53extern int eepro_probe(struct net_device *);
  54extern int at1500_probe(struct net_device *);
  55extern int at1700_probe(struct net_device *);
  56extern int fmv18x_probe(struct net_device *);
  57extern int eth16i_probe(struct net_device *);
  58extern int i82596_probe(struct net_device *);
  59extern int ewrk3_probe(struct net_device *);
  60extern int el1_probe(struct net_device *);
  61extern int wavelan_probe(struct net_device *);
  62extern int arlan_probe(struct net_device *);
  63extern int el16_probe(struct net_device *);
  64extern int elmc_probe(struct net_device *);
  65extern int skmca_probe(struct net_device *);
  66extern int elplus_probe(struct net_device *);
  67extern int ac3200_probe(struct net_device *);
  68extern int es_probe(struct net_device *);
  69extern int lne390_probe(struct net_device *);
  70extern int e2100_probe(struct net_device *);
  71extern int ni5010_probe(struct net_device *);
  72extern int ni52_probe(struct net_device *);
  73extern int ni65_probe(struct net_device *);
  74extern int sonic_probe(struct net_device *);
  75extern int SK_init(struct net_device *);
  76extern int seeq8005_probe(struct net_device *);
  77extern int smc_init( struct net_device * );
  78extern int atarilance_probe(struct net_device *);
  79extern int sun3lance_probe(struct net_device *);
  80extern int sun3_82586_probe(struct net_device *);
  81extern int apne_probe(struct net_device *);
  82extern int bionet_probe(struct net_device *);
  83extern int pamsnet_probe(struct net_device *);
  84extern int cs89x0_probe(struct net_device *dev);
  85extern int hplance_probe(struct net_device *dev);
  86extern int bagetlance_probe(struct net_device *);
  87extern int mvme147lance_probe(struct net_device *dev);
  88extern int tc515_probe(struct net_device *dev);
  89extern int lance_probe(struct net_device *dev);
  90extern int mace_probe(struct net_device *dev);
  91extern int macsonic_probe(struct net_device *dev);
  92extern int mac8390_probe(struct net_device *dev);
  93extern int mac89x0_probe(struct net_device *dev);
  94extern int mc32_probe(struct net_device *dev);
  95extern struct net_device *cops_probe(int unit);
  96extern struct net_device *ltpc_probe(void);
  97  
  98/* Detachable devices ("pocket adaptors") */
  99extern int de620_probe(struct net_device *);
 100
 101/* Fibre Channel adapters */
 102extern int iph5526_probe(struct net_device *dev);
 103
 104/* SBNI adapters */
 105extern int sbni_probe(int unit);
 106
 107struct devprobe
 108{
 109        int (*probe)(struct net_device *dev);
 110        int status;     /* non-zero if autoprobe has failed */
 111};
 112
 113/*
 114 * probe_list walks a list of probe functions and calls each so long
 115 * as a non-zero ioaddr is given, or as long as it hasn't already failed 
 116 * to find a card in the past (as recorded by "status") when asked to
 117 * autoprobe (i.e. a probe that fails to find a card when autoprobing
 118 * will not be asked to autoprobe again).  It exits when a card is found.
 119 */
 120static int __init probe_list(struct net_device *dev, struct devprobe *plist)
 121{
 122        struct devprobe *p = plist;
 123        unsigned long base_addr = dev->base_addr;
 124
 125        while (p->probe != NULL) {
 126                if (base_addr && p->probe(dev) == 0)    /* probe given addr */
 127                        return 0;
 128                else if (p->status == 0) {              /* has autoprobe failed yet? */
 129                        p->status = p->probe(dev);      /* no, try autoprobe */
 130                        if (p->status == 0)
 131                                return 0;
 132                }
 133                p++;
 134        }
 135        return -ENODEV;
 136}
 137
 138/*
 139 * This is a bit of an artificial separation as there are PCI drivers
 140 * that also probe for EISA cards (in the PCI group) and there are ISA
 141 * drivers that probe for EISA cards (in the ISA group).  These are the
 142 * legacy EISA only driver probes, and also the legacy PCI probes
 143 */
 144static struct devprobe eisa_probes[] __initdata = {
 145#ifdef CONFIG_ULTRA32 
 146        {ultra32_probe, 0},     
 147#endif
 148#ifdef CONFIG_AC3200    
 149        {ac3200_probe, 0},
 150#endif
 151#ifdef CONFIG_ES3210
 152        {es_probe, 0},
 153#endif
 154#ifdef CONFIG_LNE390
 155        {lne390_probe, 0},
 156#endif
 157        {NULL, 0},
 158};
 159
 160
 161static struct devprobe mca_probes[] __initdata = {
 162#ifdef CONFIG_NE2_MCA
 163        {ne2_probe, 0},
 164#endif
 165#ifdef CONFIG_ELMC              /* 3c523 */
 166        {elmc_probe, 0},
 167#endif
 168#ifdef CONFIG_ELMC_II           /* 3c527 */
 169        {mc32_probe, 0},
 170#endif
 171#ifdef CONFIG_SKMC              /* SKnet Microchannel */
 172        {skmca_probe, 0},
 173#endif
 174        {NULL, 0},
 175};
 176
 177/*
 178 * ISA probes that touch addresses < 0x400 (including those that also
 179 * look for EISA/PCI/MCA cards in addition to ISA cards).
 180 */
 181static struct devprobe isa_probes[] __initdata = {
 182#ifdef CONFIG_HP100             /* ISA, EISA & PCI */
 183        {hp100_probe, 0},
 184#endif  
 185#ifdef CONFIG_3C515
 186        {tc515_probe, 0},
 187#endif
 188#ifdef CONFIG_ULTRA 
 189        {ultra_probe, 0},
 190#endif
 191#ifdef CONFIG_WD80x3 
 192        {wd_probe, 0},
 193#endif
 194#ifdef CONFIG_EL2               /* 3c503 */
 195        {el2_probe, 0},
 196#endif
 197#ifdef CONFIG_HPLAN
 198        {hp_probe, 0},
 199#endif
 200#ifdef CONFIG_HPLAN_PLUS
 201        {hp_plus_probe, 0},
 202#endif
 203#ifdef CONFIG_E2100             /* Cabletron E21xx series. */
 204        {e2100_probe, 0},
 205#endif
 206#if defined(CONFIG_NE2000) || defined(CONFIG_NE2K_CBUS) /* ISA & PC-9800 CBUS (use ne2k-pci for PCI cards) */
 207        {ne_probe, 0},
 208#endif
 209#ifdef CONFIG_LANCE             /* ISA/VLB (use pcnet32 for PCI cards) */
 210        {lance_probe, 0},
 211#endif
 212#ifdef CONFIG_SMC9194
 213        {smc_init, 0},
 214#endif
 215#ifdef CONFIG_SEEQ8005 
 216        {seeq8005_probe, 0},
 217#endif
 218#ifdef CONFIG_AT1500
 219        {at1500_probe, 0},
 220#endif
 221#ifdef CONFIG_CS89x0
 222        {cs89x0_probe, 0},
 223#endif
 224#ifdef CONFIG_AT1700
 225        {at1700_probe, 0},
 226#endif
 227#ifdef CONFIG_FMV18X            /* Fujitsu FMV-181/182 */
 228        {fmv18x_probe, 0},
 229#endif
 230#ifdef CONFIG_ETH16I
 231        {eth16i_probe, 0},      /* ICL EtherTeam 16i/32 */
 232#endif
 233#ifdef CONFIG_EEXPRESS          /* Intel EtherExpress */
 234        {express_probe, 0},
 235#endif
 236#ifdef CONFIG_EEXPRESS_PRO      /* Intel EtherExpress Pro/10 */
 237        {eepro_probe, 0},
 238#endif
 239#ifdef CONFIG_EWRK3             /* DEC EtherWORKS 3 */
 240        {ewrk3_probe, 0},
 241#endif
 242#if defined(CONFIG_APRICOT) || defined(CONFIG_MVME16x_NET) || defined(CONFIG_BVME6000_NET)      /* Intel I82596 */
 243        {i82596_probe, 0},
 244#endif
 245#ifdef CONFIG_EL1               /* 3c501 */
 246        {el1_probe, 0},
 247#endif
 248#ifdef CONFIG_WAVELAN           /* WaveLAN */
 249        {wavelan_probe, 0},
 250#endif
 251#ifdef CONFIG_ARLAN             /* Aironet */
 252        {arlan_probe, 0},
 253#endif
 254#ifdef CONFIG_EL16              /* 3c507 */
 255        {el16_probe, 0},
 256#endif
 257#ifdef CONFIG_ELPLUS            /* 3c505 */
 258        {elplus_probe, 0},
 259#endif
 260#ifdef CONFIG_SK_G16
 261        {SK_init, 0},
 262#endif
 263#ifdef CONFIG_NI5010
 264        {ni5010_probe, 0},
 265#endif
 266#ifdef CONFIG_NI52
 267        {ni52_probe, 0},
 268#endif
 269#ifdef CONFIG_NI65
 270        {ni65_probe, 0},
 271#endif
 272        {NULL, 0},
 273};
 274
 275static struct devprobe parport_probes[] __initdata = {
 276#ifdef CONFIG_DE620             /* D-Link DE-620 adapter */
 277        {de620_probe, 0},
 278#endif
 279        {NULL, 0},
 280};
 281
 282static struct devprobe m68k_probes[] __initdata = {
 283#ifdef CONFIG_ATARILANCE        /* Lance-based Atari ethernet boards */
 284        {atarilance_probe, 0},
 285#endif
 286#ifdef CONFIG_SUN3LANCE         /* sun3 onboard Lance chip */
 287        {sun3lance_probe, 0},
 288#endif
 289#ifdef CONFIG_SUN3_82586        /* sun3 onboard Intel 82586 chip */
 290        {sun3_82586_probe, 0},
 291#endif
 292#ifdef CONFIG_APNE              /* A1200 PCMCIA NE2000 */
 293        {apne_probe, 0},
 294#endif
 295#ifdef CONFIG_ATARI_BIONET      /* Atari Bionet Ethernet board */
 296        {bionet_probe, 0},
 297#endif
 298#ifdef CONFIG_ATARI_PAMSNET     /* Atari PAMsNet Ethernet board */
 299        {pamsnet_probe, 0},
 300#endif
 301#ifdef CONFIG_HPLANCE           /* HP300 internal Ethernet */
 302        {hplance_probe, 0},
 303#endif
 304#ifdef CONFIG_MVME147_NET       /* MVME147 internal Ethernet */
 305        {mvme147lance_probe, 0},
 306#endif
 307#ifdef CONFIG_MACMACE           /* Mac 68k Quadra AV builtin Ethernet */
 308        {mace_probe, 0},
 309#endif
 310#ifdef CONFIG_MACSONIC          /* Mac SONIC-based Ethernet of all sorts */ 
 311        {macsonic_probe, 0},
 312#endif
 313#ifdef CONFIG_MAC8390           /* NuBus NS8390-based cards */
 314        {mac8390_probe, 0},
 315#endif
 316#ifdef CONFIG_MAC89x0
 317        {mac89x0_probe, 0},
 318#endif
 319        {NULL, 0},
 320};
 321
 322static struct devprobe mips_probes[] __initdata = {
 323#ifdef CONFIG_MIPS_JAZZ_SONIC
 324        {sonic_probe, 0},
 325#endif
 326#ifdef CONFIG_BAGETLANCE        /* Lance-based Baget ethernet boards */
 327        {bagetlance_probe, 0},
 328#endif
 329        {NULL, 0},
 330};
 331
 332/*
 333 * Unified ethernet device probe, segmented per architecture and
 334 * per bus interface. This drives the legacy devices only for now.
 335 */
 336 
 337static int __init ethif_probe(int unit)
 338{
 339        struct net_device *dev;
 340        int err = -ENODEV;
 341
 342        dev = alloc_etherdev(0);
 343        if (!dev)
 344                return -ENOMEM;
 345
 346        sprintf(dev->name, "eth%d", unit);
 347        netdev_boot_setup_check(dev);
 348
 349        /* 
 350         * Backwards compatibility - historically an I/O base of 1 was 
 351         * used to indicate not to probe for this ethN interface 
 352         */
 353        if (dev->base_addr == 1) {
 354                free_netdev(dev);
 355                return -ENXIO;
 356        }
 357
 358        /* 
 359         * The arch specific probes are 1st so that any on-board ethernet
 360         * will be probed before other ISA/EISA/MCA/PCI bus cards.
 361         */
 362        if (probe_list(dev, m68k_probes) == 0 ||
 363            probe_list(dev, mips_probes) == 0 ||
 364            probe_list(dev, eisa_probes) == 0 ||
 365            probe_list(dev, mca_probes) == 0 ||
 366            probe_list(dev, isa_probes) == 0 ||
 367            probe_list(dev, parport_probes) == 0) 
 368                err = register_netdev(dev);
 369
 370        if (err)
 371                free_netdev(dev);
 372        return err;
 373
 374}
 375
 376#ifdef CONFIG_TR
 377/* Token-ring device probe */
 378extern int ibmtr_probe(struct net_device *);
 379extern int sk_isa_probe(struct net_device *);
 380extern int proteon_probe(struct net_device *);
 381extern int smctr_probe(struct net_device *);
 382
 383static __init int trif_probe(int unit)
 384{
 385        struct net_device *dev;
 386        int err = -ENODEV;
 387        
 388        dev = alloc_trdev(0);
 389        if (!dev)
 390                return -ENOMEM;
 391
 392        sprintf(dev->name, "tr%d", unit);
 393        netdev_boot_setup_check(dev);
 394        if (
 395#ifdef CONFIG_IBMTR
 396            ibmtr_probe(dev) == 0  ||
 397#endif
 398#ifdef CONFIG_SKISA
 399            sk_isa_probe(dev) == 0 || 
 400#endif
 401#ifdef CONFIG_PROTEON
 402            proteon_probe(dev) == 0 ||
 403#endif
 404#ifdef CONFIG_SMCTR
 405            smctr_probe(dev) == 0 ||
 406#endif
 407            0 ) 
 408                err = register_netdev(dev);
 409                
 410        if (err)
 411                free_netdev(dev);
 412        return err;
 413
 414}
 415#endif
 416
 417        
 418/*
 419 *      The loopback device is global so it can be directly referenced
 420 *      by the network code. Also, it must be first on device list.
 421 */
 422extern int loopback_init(void);
 423
 424/*  Statically configured drivers -- order matters here. */
 425static int __init net_olddevs_init(void)
 426{
 427        int num;
 428
 429        if (loopback_init()) {
 430                printk(KERN_ERR "Network loopback device setup failed\n");
 431        }
 432
 433        
 434#ifdef CONFIG_SBNI
 435        for (num = 0; num < 8; ++num)
 436                sbni_probe(num);
 437#endif
 438#ifdef CONFIG_TR
 439        for (num = 0; num < 8; ++num)
 440                trif_probe(num);
 441#endif
 442        for (num = 0; num < 8; ++num)
 443                ethif_probe(num);
 444
 445#ifdef CONFIG_COPS
 446        cops_probe(0);
 447        cops_probe(1);
 448        cops_probe(2);
 449#endif
 450#ifdef CONFIG_LTPC
 451        ltpc_probe();
 452#endif
 453
 454        return 0;
 455}
 456
 457device_initcall(net_olddevs_init);
 458
 459/*
 460 * The @dev_base list is protected by @dev_base_lock and the rtln
 461 * semaphore.
 462 *
 463 * Pure readers hold dev_base_lock for reading.
 464 *
 465 * Writers must hold the rtnl semaphore while they loop through the
 466 * dev_base list, and hold dev_base_lock for writing when they do the
 467 * actual updates.  This allows pure readers to access the list even
 468 * while a writer is preparing to update it.
 469 *
 470 * To put it another way, dev_base_lock is held for writing only to
 471 * protect against pure readers; the rtnl semaphore provides the
 472 * protection against other writers.
 473 *
 474 * See, for example usages, register_netdevice() and
 475 * unregister_netdevice(), which must be called with the rtnl
 476 * semaphore held.
 477 */
 478struct net_device *dev_base;
 479rwlock_t dev_base_lock = RW_LOCK_UNLOCKED;
 480
 481EXPORT_SYMBOL(dev_base);
 482EXPORT_SYMBOL(dev_base_lock);
 483
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.