root/drivers/net/net_init.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. net_dev_init
  2. init_etherdev
  3. ether_setup
  4. ether_config
  5. register_netdev
  6. unregister_netdev

   1 /* netdrv_init.c: Initialization for network devices. */
   2 /*
   3         Written 1993 by Donald Becker.
   4         Copyright 1993 United States Government as represented by the Director,
   5         National Security Agency.  This software may only be used and distributed
   6         according to the terms of the GNU Public License as modified by SRC,
   7         incorported herein by reference.
   8 
   9         The author may be reached as becker@super.org or
  10         C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  11 
  12         This file contains the initialization for the "pl14+" style ethernet
  13         drivers.  It should eventually replace most of drivers/net/Space.c.
  14         It's primary advantage is that it's able to allocate low-memory buffers.
  15         A secondary advantage is that the dangerous NE*000 netcards can reserve
  16         their I/O port region before the SCSI probes start.
  17 
  18         register_netdev()/unregister_netdev() by Bjorn Ekwall <bj0rn@blox.se>
  19 */
  20 
  21 #include <linux/config.h>
  22 #include <linux/kernel.h>
  23 #include <linux/sched.h>
  24 #include <linux/types.h>
  25 #include <linux/fs.h>
  26 #include <linux/malloc.h>
  27 #include <linux/if_ether.h>
  28 #include <linux/string.h>
  29 #include <linux/netdevice.h>
  30 #include <linux/etherdevice.h>
  31 
  32 /* The network devices currently exist only in the socket namespace, so these
  33    entries are unused.  The only ones that make sense are
  34     open        start the ethercard
  35     close       stop  the ethercard
  36     ioctl       To get statistics, perhaps set the interface port (AUI, BNC, etc.)
  37    One can also imagine getting raw packets using
  38     read & write
  39    but this is probably better handled by a raw packet socket.
  40 
  41    Given that almost all of these functions are handled in the current
  42    socket-based scheme, putting ethercard devices in /dev/ seems pointless.
  43    
  44    [Removed all support for /dev network devices. When someone adds streams then
  45     by magic we get them, but otherwise they are un-needed and a space waste]
  46 */
  47 
  48 /* The next device number/name to assign: "eth0", "eth1", etc. */
  49 static int next_ethdev_number = 0;
  50 
  51 unsigned long lance_init(unsigned long mem_start, unsigned long mem_end);
  52 
  53 /*
  54   net_dev_init() is our network device initialization routine.
  55   It's called from init/main.c with the start and end of free memory,
  56   and returns the new start of free memory.
  57   */
  58 
  59 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61 
  62 #if defined(CONFIG_LANCE)                       /* Note this is _not_ CONFIG_AT1500. */
  63         mem_start = lance_init(mem_start, mem_end);
  64 #endif
  65 #if defined(CONFIG_PI)
  66         mem_start = pi_init(mem_start, mem_end);
  67 #endif  
  68         return mem_start;
  69 }
  70 
  71 /* Fill in the fields of the device structure with ethernet-generic values.
  72 
  73    If no device structure is passed, a new one is constructed, complete with
  74    a SIZEOF_PRIVATE private data area.
  75 
  76    If an empty string area is passed as dev->name, or a new structure is made,
  77    a new name string is constructed.  The passed string area should be 8 bytes
  78    long.
  79  */
  80 
  81 struct device *init_etherdev(struct device *dev, int sizeof_private,
     /* [previous][next][first][last][top][bottom][index][help] */
  82                                                          unsigned long *mem_startp)
  83 {
  84         int i;
  85         int new_device = 0;
  86 
  87         if (dev == NULL) {
  88                 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
  89                         + sizeof_private;
  90                 if (mem_startp && *mem_startp ) {
  91                         dev = (struct device *)*mem_startp;
  92                         *mem_startp += alloc_size;
  93                 } else
  94                         dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
  95                 memset(dev, 0, sizeof(alloc_size));
  96                 dev->name = (char *)(dev + 1);
  97                 if (sizeof_private)
  98                         dev->priv = dev->name + sizeof("eth%d ");
  99                 new_device = 1;
 100         }
 101 
 102         if (dev->name  &&  dev->name[0] == '\0')
 103                 sprintf(dev->name, "eth%d", next_ethdev_number++);
 104 
 105         for (i = 0; i < DEV_NUMBUFFS; i++)
 106                 skb_queue_head_init(&dev->buffs[i]);
 107         
 108         dev->hard_header        = eth_header;
 109         dev->rebuild_header     = eth_rebuild_header;
 110         dev->type_trans         = eth_type_trans;
 111         
 112         dev->type                       = ARPHRD_ETHER;
 113         dev->hard_header_len = ETH_HLEN;
 114         dev->mtu                        = 1500; /* eth_mtu */
 115         dev->addr_len           = ETH_ALEN;
 116         for (i = 0; i < ETH_ALEN; i++) {
 117                 dev->broadcast[i]=0xff;
 118         }
 119         
 120         /* New-style flags. */
 121         dev->flags                      = IFF_BROADCAST;
 122         dev->family                     = AF_INET;
 123         dev->pa_addr            = 0;
 124         dev->pa_brdaddr         = 0;
 125         dev->pa_mask            = 0;
 126         dev->pa_alen            = sizeof(unsigned long);
 127         
 128         if (new_device) {
 129                 /* Append the device to the device queue. */
 130                 struct device **old_devp = &dev_base;
 131                 while ((*old_devp)->next)
 132                         old_devp = & (*old_devp)->next;
 133                 (*old_devp)->next = dev;
 134                 dev->next = 0;
 135         }
 136         return dev;
 137 }
 138 
 139 void ether_setup(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141         int i;
 142         /* Fill in the fields of the device structure with ethernet-generic values.
 143            This should be in a common file instead of per-driver.  */
 144         for (i = 0; i < DEV_NUMBUFFS; i++)
 145                 skb_queue_head_init(&dev->buffs[i]);
 146 
 147         dev->hard_header        = eth_header;
 148         dev->rebuild_header = eth_rebuild_header;
 149         dev->type_trans = eth_type_trans;
 150 
 151         dev->type               = ARPHRD_ETHER;
 152         dev->hard_header_len = ETH_HLEN;
 153         dev->mtu                = 1500; /* eth_mtu */
 154         dev->addr_len   = ETH_ALEN;
 155         for (i = 0; i < ETH_ALEN; i++) {
 156                 dev->broadcast[i]=0xff;
 157         }
 158 
 159         /* New-style flags. */
 160         dev->flags              = IFF_BROADCAST;
 161         dev->family             = AF_INET;
 162         dev->pa_addr    = 0;
 163         dev->pa_brdaddr = 0;
 164         dev->pa_mask    = 0;
 165         dev->pa_alen    = sizeof(unsigned long);
 166 }
 167 
 168 int ether_config(struct device *dev, struct ifmap *map)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170         if (map->mem_start != (u_long)(-1))
 171                 dev->mem_start = map->mem_start;
 172         if (map->mem_end != (u_long)(-1))
 173                 dev->mem_end = map->mem_end;
 174         if (map->base_addr != (u_short)(-1))
 175                 dev->base_addr = map->base_addr;
 176         if (map->irq != (u_char)(-1))
 177                 dev->irq = map->irq;
 178         if (map->dma != (u_char)(-1))
 179                 dev->dma = map->dma;
 180         if (map->port != (u_char)(-1))
 181                 dev->if_port = map->port;
 182         return 0;
 183 }
 184 
 185 int register_netdev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 186 {
 187         struct device *d = dev_base;
 188         unsigned long flags;
 189         
 190         save_flags(flags);
 191         cli();
 192 
 193         if (dev && dev->init) 
 194         {
 195                 if (dev->init(dev) != 0)
 196                 {
 197                         restore_flags(flags);
 198                         return -EIO;
 199                 }
 200                 
 201                 if (dev->name  &&  dev->name[0] == '\0')
 202                         sprintf(dev->name, "eth%d", next_ethdev_number++);
 203 
 204                 /* Add device to end of chain */
 205                 if (dev_base) 
 206                 {
 207                         while (d->next)
 208                                 d = d->next;
 209                         d->next = dev;
 210                 }
 211                 else
 212                         dev_base = dev;
 213                 dev->next = NULL;
 214         }
 215         restore_flags(flags);
 216         return 0;
 217 }
 218 
 219 void unregister_netdev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 220 {
 221         struct device *d = dev_base;
 222         unsigned long flags;
 223         
 224         save_flags(flags);
 225         cli();
 226 
 227         printk("unregister_netdev: device ");
 228         if (dev) {
 229                 if (dev->start)
 230                         printk("'%s' busy", dev->name);
 231                 else {
 232                         if (dev_base == dev)
 233                                 dev_base = dev->next;
 234                         else {
 235                                 while (d && (d->next != dev))
 236                                         d = d->next;
 237 
 238                                 if (d && (d->next == dev)) {
 239                                         d->next = dev->next;
 240                                         printk("'%s' unlinked", dev->name);
 241                                 }
 242                                 else
 243                                         printk("'%s' not found", dev->name);
 244                         }
 245                 }
 246         }
 247         else
 248                 printk("was NULL");
 249         printk("\n");
 250         restore_flags(flags);
 251 }
 252 
 253 
 254 /*
 255  * Local variables:
 256  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c net_init.c"
 257  *  version-control: t
 258  *  kept-new-versions: 5
 259  *  tab-width: 4
 260  * End:
 261  */

/* [previous][next][first][last][top][bottom][index][help] */