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

   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 
  19 #include <linux/config.h>
  20 #include <linux/kernel.h>
  21 #include <linux/sched.h>
  22 #include <linux/types.h>
  23 #include <linux/fs.h>
  24 #include <linux/malloc.h>
  25 #include <linux/if_ether.h>
  26 #include <linux/string.h>
  27 #include <linux/netdevice.h>
  28 #include <linux/etherdevice.h>
  29 
  30 /* The network devices currently exist only in the socket namespace, so these
  31    entries are unused.  The only ones that make sense are
  32     open        start the ethercard
  33     close       stop  the ethercard
  34     ioctl       To get statistics, perhaps set the interface port (AUI, BNC, etc.)
  35    One can also imagine getting raw packets using
  36     read & write
  37    but this is probably better handled by a raw packet socket.
  38 
  39    Given that almost all of these functions are handled in the current
  40    socket-based scheme, putting ethercard devices in /dev/ seems pointless.
  41    
  42    [Removed all support for /dev network devices. When someone adds streams then
  43     by magic we get them, but otherwise they are un-needed and a space waste]
  44 */
  45 
  46 /* The next device number/name to assign: "eth0", "eth1", etc. */
  47 static int next_ethdev_number = 0;
  48 
  49 unsigned long lance_init(unsigned long mem_start, unsigned long mem_end);
  50 
  51 /*
  52   net_dev_init() is our network device initialization routine.
  53   It's called from init/main.c with the start and end of free memory,
  54   and returns the new start of free memory.
  55   */
  56 
  57 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59 
  60 #if defined(CONFIG_LANCE)                       /* Note this is _not_ CONFIG_AT1500. */
  61         mem_start = lance_init(mem_start, mem_end);
  62 #endif
  63 
  64         return mem_start;
  65 }
  66 
  67 /* Fill in the fields of the device structure with ethernet-generic values.
  68 
  69    If no device structure is passed, a new one is constructed, complete with
  70    a SIZEOF_PRIVATE private data area.
  71 
  72    If an empty string area is passed as dev->name, or a new structure is made,
  73    a new name string is constructed.  The passed string area should be 8 bytes
  74    long.
  75  */
  76 
  77 struct device *init_etherdev(struct device *dev, int sizeof_private,
     /* [previous][next][first][last][top][bottom][index][help] */
  78                                                          unsigned long *mem_startp)
  79 {
  80         int i;
  81         int new_device = 0;
  82 
  83         if (dev == NULL) {
  84                 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
  85                         + sizeof_private;
  86                 if (mem_startp && *mem_startp ) {
  87                         dev = (struct device *)*mem_startp;
  88                         *mem_startp += alloc_size;
  89                 } else
  90                         dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
  91                 memset(dev, 0, sizeof(alloc_size));
  92                 dev->name = (char *)(dev + 1);
  93                 if (sizeof_private)
  94                         dev->priv = dev->name + sizeof("eth%d ");
  95                 new_device = 1;
  96         }
  97 
  98         if (dev->name  &&  dev->name[0] == '\0')
  99                 sprintf(dev->name, "eth%d", next_ethdev_number++);
 100 
 101         for (i = 0; i < DEV_NUMBUFFS; i++)
 102                 skb_queue_head_init(&dev->buffs[i]);
 103         
 104         dev->hard_header        = eth_header;
 105         dev->rebuild_header     = eth_rebuild_header;
 106         dev->type_trans         = eth_type_trans;
 107         
 108         dev->type                       = ARPHRD_ETHER;
 109         dev->hard_header_len = ETH_HLEN;
 110         dev->mtu                        = 1500; /* eth_mtu */
 111         dev->addr_len           = ETH_ALEN;
 112         for (i = 0; i < ETH_ALEN; i++) {
 113                 dev->broadcast[i]=0xff;
 114         }
 115         
 116         /* New-style flags. */
 117         dev->flags                      = IFF_BROADCAST;
 118         dev->family                     = AF_INET;
 119         dev->pa_addr            = 0;
 120         dev->pa_brdaddr         = 0;
 121         dev->pa_mask            = 0;
 122         dev->pa_alen            = sizeof(unsigned long);
 123         
 124         if (new_device) {
 125                 /* Append the device to the device queue. */
 126                 struct device **old_devp = &dev_base;
 127                 while ((*old_devp)->next)
 128                         old_devp = & (*old_devp)->next;
 129                 (*old_devp)->next = dev;
 130                 dev->next = 0;
 131         }
 132         return dev;
 133 }
 134 
 135 void ether_setup(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 136 {
 137         int i;
 138         /* Fill in the fields of the device structure with ethernet-generic values.
 139            This should be in a common file instead of per-driver.  */
 140         for (i = 0; i < DEV_NUMBUFFS; i++)
 141                 skb_queue_head_init(&dev->buffs[i]);
 142 
 143         dev->hard_header        = eth_header;
 144         dev->rebuild_header = eth_rebuild_header;
 145         dev->type_trans = eth_type_trans;
 146 
 147         dev->type               = ARPHRD_ETHER;
 148         dev->hard_header_len = ETH_HLEN;
 149         dev->mtu                = 1500; /* eth_mtu */
 150         dev->addr_len   = ETH_ALEN;
 151         for (i = 0; i < ETH_ALEN; i++) {
 152                 dev->broadcast[i]=0xff;
 153         }
 154 
 155         /* New-style flags. */
 156         dev->flags              = IFF_BROADCAST;
 157         dev->family             = AF_INET;
 158         dev->pa_addr    = 0;
 159         dev->pa_brdaddr = 0;
 160         dev->pa_mask    = 0;
 161         dev->pa_alen    = sizeof(unsigned long);
 162 }
 163 
 164 
 165 
 166 /*
 167  * Local variables:
 168  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c net_init.c"
 169  *  version-control: t
 170  *  kept-new-versions: 5
 171  *  tab-width: 4
 172  * End:
 173  */

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