This source file includes following definitions.
- net_dev_init
- init_etherdev
- ether_setup
- ether_config
- register_netdev
- unregister_netdev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <linux/config.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/types.h>
24 #include <linux/fs.h>
25 #include <linux/malloc.h>
26 #include <linux/if_ether.h>
27 #include <linux/string.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 #define MAX_ETH_CARDS 16
50 static struct device *ethdev_index[MAX_ETH_CARDS];
51
52 unsigned long lance_init(unsigned long mem_start, unsigned long mem_end);
53 unsigned long pi_init(unsigned long mem_start, unsigned long mem_end);
54 unsigned long apricot_init(unsigned long mem_start, unsigned long mem_end);
55 unsigned long dec21040_init(unsigned long mem_start, unsigned long mem_end);
56
57
58
59
60
61
62
63 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
64 {
65
66
67
68
69 #if defined(CONFIG_LANCE)
70 mem_start = lance_init(mem_start, mem_end);
71 #endif
72 #if defined(CONFIG_PI)
73 mem_start = pi_init(mem_start, mem_end);
74 #endif
75 #if defined(CONFIG_DEC_ELCP)
76 mem_start = dec21040_init(mem_start, mem_end);
77 #endif
78 return mem_start;
79 }
80
81
82
83
84
85
86
87
88
89
90
91 struct device *
92 init_etherdev(struct device *dev, int sizeof_priv, unsigned long *mem_startp)
93 {
94 int new_device = 0;
95 int i;
96
97
98 if (dev == NULL) {
99 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
100 + sizeof_priv + 3;
101 struct device *cur_dev;
102 char pname[8];
103
104 for (i = 0; i < MAX_ETH_CARDS; ++i)
105 if (ethdev_index[i] == NULL) {
106 sprintf(pname, "eth%d", i);
107 for (cur_dev = dev_base; cur_dev; cur_dev = cur_dev->next)
108 if (strcmp(pname, cur_dev->name) == 0) {
109 dev = cur_dev;
110 dev->init = NULL;
111 sizeof_priv = (sizeof_priv + 3) & ~3;
112 if (mem_startp && *mem_startp ) {
113 dev->priv = (void*) *mem_startp;
114 *mem_startp += sizeof_priv;
115 } else
116 dev->priv = kmalloc(sizeof_priv, GFP_KERNEL);
117 memset(dev->priv, 0, sizeof_priv);
118 goto found;
119 }
120 }
121
122 alloc_size &= ~3;
123
124 if (mem_startp && *mem_startp ) {
125 dev = (struct device *)*mem_startp;
126 *mem_startp += alloc_size;
127 } else
128 dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
129 memset(dev, 0, alloc_size);
130 if (sizeof_priv)
131 dev->priv = (void *) (dev + 1);
132 dev->name = sizeof_priv + (char *)(dev + 1);
133 new_device = 1;
134 }
135
136 found:
137
138 if (dev->name &&
139 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
140 for (i = 0; i < MAX_ETH_CARDS; ++i)
141 if (ethdev_index[i] == NULL) {
142 sprintf(dev->name, "eth%d", i);
143 ethdev_index[i] = dev;
144 break;
145 }
146 }
147
148 ether_setup(dev);
149
150 if (new_device) {
151
152 struct device **old_devp = &dev_base;
153 while ((*old_devp)->next)
154 old_devp = & (*old_devp)->next;
155 (*old_devp)->next = dev;
156 dev->next = 0;
157 }
158 return dev;
159 }
160
161 void ether_setup(struct device *dev)
162 {
163 int i;
164
165
166 for (i = 0; i < DEV_NUMBUFFS; i++)
167 skb_queue_head_init(&dev->buffs[i]);
168
169
170 if (dev->name && (strncmp(dev->name, "eth", 3) == 0)) {
171 i = simple_strtoul(dev->name + 3, NULL, 0);
172 if (ethdev_index[i] == NULL) {
173 ethdev_index[i] = dev;
174 }
175 else if (dev != ethdev_index[i]) {
176
177 printk("ether_setup: Ouch! Someone else took %s\n",
178 dev->name);
179 }
180 }
181
182 dev->hard_header = eth_header;
183 dev->rebuild_header = eth_rebuild_header;
184 dev->type_trans = eth_type_trans;
185
186 dev->type = ARPHRD_ETHER;
187 dev->hard_header_len = ETH_HLEN;
188 dev->mtu = 1500;
189 dev->addr_len = ETH_ALEN;
190 for (i = 0; i < ETH_ALEN; i++) {
191 dev->broadcast[i]=0xff;
192 }
193
194
195 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
196 dev->family = AF_INET;
197 dev->pa_addr = 0;
198 dev->pa_brdaddr = 0;
199 dev->pa_mask = 0;
200 dev->pa_alen = sizeof(unsigned long);
201 }
202
203 int ether_config(struct device *dev, struct ifmap *map)
204 {
205 if (map->mem_start != (u_long)(-1))
206 dev->mem_start = map->mem_start;
207 if (map->mem_end != (u_long)(-1))
208 dev->mem_end = map->mem_end;
209 if (map->base_addr != (u_short)(-1))
210 dev->base_addr = map->base_addr;
211 if (map->irq != (u_char)(-1))
212 dev->irq = map->irq;
213 if (map->dma != (u_char)(-1))
214 dev->dma = map->dma;
215 if (map->port != (u_char)(-1))
216 dev->if_port = map->port;
217 return 0;
218 }
219
220 int register_netdev(struct device *dev)
221 {
222 struct device *d = dev_base;
223 unsigned long flags;
224 int i=MAX_ETH_CARDS;
225
226 save_flags(flags);
227 cli();
228
229 if (dev && dev->init) {
230 if (dev->name &&
231 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
232 for (i = 0; i < MAX_ETH_CARDS; ++i)
233 if (ethdev_index[i] == NULL) {
234 sprintf(dev->name, "eth%d", i);
235 printk("loading device '%s'...\n", dev->name);
236 ethdev_index[i] = dev;
237 break;
238 }
239 }
240
241 if (dev->init(dev) != 0) {
242 if (i < MAX_ETH_CARDS) ethdev_index[i] = NULL;
243 restore_flags(flags);
244 return -EIO;
245 }
246
247
248 if (dev_base) {
249 while (d->next)
250 d = d->next;
251 d->next = dev;
252 }
253 else
254 dev_base = dev;
255 dev->next = NULL;
256 }
257 restore_flags(flags);
258 return 0;
259 }
260
261 void unregister_netdev(struct device *dev)
262 {
263 struct device *d = dev_base;
264 unsigned long flags;
265 int i;
266
267 save_flags(flags);
268 cli();
269
270 printk("unregister_netdev: device ");
271
272 if (dev == NULL) {
273 printk("was NULL\n");
274 restore_flags(flags);
275 return;
276 }
277
278 if (dev->start)
279 printk("'%s' busy\n", dev->name);
280 else {
281 if (dev_base == dev)
282 dev_base = dev->next;
283 else {
284 while (d && (d->next != dev))
285 d = d->next;
286
287 if (d && (d->next == dev)) {
288 d->next = dev->next;
289 printk("'%s' unlinked\n", dev->name);
290 }
291 else {
292 printk("'%s' not found\n", dev->name);
293 restore_flags(flags);
294 return;
295 }
296 }
297 for (i = 0; i < MAX_ETH_CARDS; ++i) {
298 if (ethdev_index[i] == dev) {
299 ethdev_index[i] = NULL;
300 break;
301 }
302 }
303 }
304 restore_flags(flags);
305 }
306
307
308
309
310
311
312
313
314
315
316