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 <memory.h>
27 #include "dev.h"
28 #include "eth.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
43 /* The next device number/name to assign: "eth0", "eth1", etc. */
44 static int next_ethdev_number = 0;
45
46 #ifdef NET_MAJOR_NUM
47 static struct file_operations netcard_fops = {
48 NULL, /* lseek */
49 NULL, /* read */
50 NULL, /* write */
51 NULL, /* readdir */
52 NULL, /* select */
53 NULL, /* ioctl */
54 NULL, /* mmap */
55 NULL, /* open */
56 NULL, /* release */
57 NULL /* fsync */
58 };
59 #endif
60
61 unsigned long lance_init(unsigned long mem_start, unsigned long mem_end);
62
63 /*
64 net_dev_init() is our network device initialization routine.
65 It's called from init/main.c with the start and end of free memory,
66 and returns the new start of free memory.
67 */
68
69 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
70 {
71
72 #ifdef NET_MAJOR_NUM
73 if (register_chrdev(NET_MAJOR_NUM, "network",&netcard_fops))
74 printk("WARNING: Unable to get major %d for the network devices.\n",
75 NET_MAJOR_NUM);
76 #endif
77
78 #if defined(CONFIG_LANCE) /* Note this is _not_ CONFIG_AT1500. */
79 mem_start = lance_init(mem_start, mem_end);
80 #endif
81
82 return mem_start;
83 }
84
85 /* Fill in the fields of the device structure with ethernet-generic values.
86
87 If no device structure is passed, a new one is constructed, complete with
88 a SIZEOF_PRIVATE private data area.
89
90 If an empty string area is passed as dev->name, or a new structure is made,
91 a new name string is constructed. The passed string area should be 8 bytes
92 long.
93 */
94
95 struct device *init_etherdev(struct device *dev, int sizeof_private,
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
96 unsigned long *mem_startp)
97 {
98 int i;
99 int new_device = 0;
100
101 if (dev == NULL) {
102 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
103 + sizeof_private;
104 if (mem_startp && *mem_startp ) {
105 dev = (struct device *)*mem_startp;
106 *mem_startp += alloc_size;
107 } else
108 dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
109 memset(dev, 0, sizeof(alloc_size));
110 dev->name = (char *)(dev + 1);
111 if (sizeof_private)
112 dev->priv = dev->name + sizeof("eth%d ");
113 new_device = 1;
114 }
115
116 if (dev->name && dev->name[0] == '\0')
117 sprintf(dev->name, "eth%d", next_ethdev_number++);
118
119 for (i = 0; i < DEV_NUMBUFFS; i++)
120 dev->buffs[i] = NULL;
121
122 dev->hard_header = eth_header;
123 dev->add_arp = eth_add_arp;
124 dev->queue_xmit = dev_queue_xmit;
125 dev->rebuild_header = eth_rebuild_header;
126 dev->type_trans = eth_type_trans;
127
128 dev->type = ARPHRD_ETHER;
129 dev->hard_header_len = ETH_HLEN;
130 dev->mtu = 1500; /* eth_mtu */
131 dev->addr_len = ETH_ALEN;
132 for (i = 0; i < ETH_ALEN; i++) {
133 dev->broadcast[i]=0xff;
134 }
135
136 /* New-style flags. */
137 dev->flags = IFF_BROADCAST;
138 dev->family = AF_INET;
139 dev->pa_addr = 0;
140 dev->pa_brdaddr = 0;
141 dev->pa_mask = 0;
142 dev->pa_alen = sizeof(unsigned long);
143
144 if (new_device) {
145 /* Append the device to the device queue. */
146 struct device **old_devp = &dev_base;
147 while ((*old_devp)->next)
148 old_devp = & (*old_devp)->next;
149 (*old_devp)->next = dev;
150 dev->next = 0;
151 }
152 return dev;
153 }
154
155
156 /*
157 * Local variables:
158 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c net_init.c"
159 * version-control: t
160 * kept-new-versions: 5
161 * tab-width: 4
162 * End:
163 */