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. register_netdev
  5. 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 register_netdev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170         struct device *d = dev_base;
 171         unsigned long flags;
 172         
 173         save_flags(flags);
 174         cli();
 175 
 176         if (dev && dev->init) 
 177         {
 178                 if (dev->init(dev) != 0)
 179                 {
 180                         restore_flags(flags);
 181                         return -EIO;
 182                 }
 183                 
 184                 if (dev->name  &&  dev->name[0] == '\0')
 185                         sprintf(dev->name, "eth%d", next_ethdev_number++);
 186 
 187                 /* Add device to end of chain */
 188                 if (dev_base) 
 189                 {
 190                         while (d->next)
 191                                 d = d->next;
 192                         d->next = dev;
 193                 }
 194                 else
 195                         dev_base = dev;
 196                 dev->next = NULL;
 197         }
 198         restore_flags(flags);
 199         return 0;
 200 }
 201 
 202 void unregister_netdev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 203 {
 204         struct device *d = dev_base;
 205         unsigned long flags;
 206         
 207         save_flags(flags);
 208         cli();
 209 
 210         printk("unregister_netdev: device ");
 211         if (dev) {
 212                 if (dev->start)
 213                         printk("'%s' busy", dev->name);
 214                 else {
 215                         if (dev_base == dev)
 216                                 dev_base = dev->next;
 217                         else {
 218                                 while (d && (d->next != dev))
 219                                         d = d->next;
 220 
 221                                 if (d && (d->next == dev)) {
 222                                         d->next = dev->next;
 223                                         printk("'%s' unlinked", dev->name);
 224                                 }
 225                                 else
 226                                         printk("'%s' not found", dev->name);
 227                         }
 228                 }
 229         }
 230         else
 231                 printk("was NULL");
 232         printk("\n");
 233         restore_flags(flags);
 234 }
 235 
 236 
 237 /*
 238  * Local variables:
 239  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c net_init.c"
 240  *  version-control: t
 241  *  kept-new-versions: 5
 242  *  tab-width: 4
 243  * End:
 244  */

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