This source file includes following definitions.
- net_dev_init
- init_etherdev
- eth_mac_addr
- ether_setup
- tr_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/if_arp.h>
28 #include <linux/string.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/trdevice.h>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #define MAX_ETH_CARDS 16
52 static struct device *ethdev_index[MAX_ETH_CARDS];
53
54 unsigned long lance_init(unsigned long mem_start, unsigned long mem_end);
55 unsigned long pi_init(unsigned long mem_start, unsigned long mem_end);
56 unsigned long apricot_init(unsigned long mem_start, unsigned long mem_end);
57 unsigned long dec21040_init(unsigned long mem_start, unsigned long mem_end);
58
59
60
61
62
63
64
65 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
66 {
67
68
69
70
71 #if defined(CONFIG_LANCE)
72 mem_start = lance_init(mem_start, mem_end);
73 #endif
74 #if defined(CONFIG_PI)
75 mem_start = pi_init(mem_start, mem_end);
76 #endif
77 #if defined(CONFIG_DEC_ELCP)
78 mem_start = dec21040_init(mem_start, mem_end);
79 #endif
80 return mem_start;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 struct device *
94 init_etherdev(struct device *dev, int sizeof_priv, unsigned long *mem_startp)
95 {
96 int new_device = 0;
97 int i;
98
99
100 if (dev == NULL) {
101 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
102 + sizeof_priv + 3;
103 struct device *cur_dev;
104 char pname[8];
105
106 for (i = 0; i < MAX_ETH_CARDS; ++i)
107 if (ethdev_index[i] == NULL) {
108 sprintf(pname, "eth%d", i);
109 for (cur_dev = dev_base; cur_dev; cur_dev = cur_dev->next)
110 if (strcmp(pname, cur_dev->name) == 0) {
111 dev = cur_dev;
112 dev->init = NULL;
113 sizeof_priv = (sizeof_priv + 3) & ~3;
114 if (mem_startp && *mem_startp ) {
115 dev->priv = (void*) *mem_startp;
116 *mem_startp += sizeof_priv;
117 } else
118 dev->priv = sizeof_priv
119 ? kmalloc(sizeof_priv, GFP_KERNEL)
120 : NULL;
121 if (dev->priv) memset(dev->priv, 0, sizeof_priv);
122 goto found;
123 }
124 }
125
126 alloc_size &= ~3;
127
128 if (mem_startp && *mem_startp ) {
129 dev = (struct device *)*mem_startp;
130 *mem_startp += alloc_size;
131 } else
132 dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
133 memset(dev, 0, alloc_size);
134 if (sizeof_priv)
135 dev->priv = (void *) (dev + 1);
136 dev->name = sizeof_priv + (char *)(dev + 1);
137 new_device = 1;
138 }
139
140 found:
141
142 if (dev->name &&
143 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
144 for (i = 0; i < MAX_ETH_CARDS; ++i)
145 if (ethdev_index[i] == NULL) {
146 sprintf(dev->name, "eth%d", i);
147 ethdev_index[i] = dev;
148 break;
149 }
150 }
151
152 ether_setup(dev);
153
154 if (new_device) {
155
156 struct device **old_devp = &dev_base;
157 while ((*old_devp)->next)
158 old_devp = & (*old_devp)->next;
159 (*old_devp)->next = dev;
160 dev->next = 0;
161 }
162 return dev;
163 }
164
165
166 static int eth_mac_addr(struct device *dev, void * addr)
167 {
168 struct ifreq * ifr = (struct ifreq *) addr;
169
170 if(dev->start)
171 return -EBUSY;
172 memcpy(dev->dev_addr, ifr->ifr_hwaddr.sa_data,dev->hard_header_len);
173 return 0;
174 }
175
176 void ether_setup(struct device *dev)
177 {
178 int i;
179
180
181 for (i = 0; i < DEV_NUMBUFFS; i++)
182 skb_queue_head_init(&dev->buffs[i]);
183
184
185 if (dev->name && (strncmp(dev->name, "eth", 3) == 0)) {
186 i = simple_strtoul(dev->name + 3, NULL, 0);
187 if (ethdev_index[i] == NULL) {
188 ethdev_index[i] = dev;
189 }
190 else if (dev != ethdev_index[i]) {
191
192 printk("ether_setup: Ouch! Someone else took %s\n",
193 dev->name);
194 }
195 }
196
197 dev->hard_header = eth_header;
198 dev->rebuild_header = eth_rebuild_header;
199 dev->set_mac_address = eth_mac_addr;
200 dev->header_cache = eth_header_cache;
201
202 dev->type = ARPHRD_ETHER;
203 dev->hard_header_len = ETH_HLEN;
204 dev->mtu = 1500;
205 dev->addr_len = ETH_ALEN;
206 for (i = 0; i < ETH_ALEN; i++) {
207 dev->broadcast[i]=0xff;
208 }
209
210
211 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
212 dev->family = AF_INET;
213 dev->pa_addr = 0;
214 dev->pa_brdaddr = 0;
215 dev->pa_mask = 0;
216 dev->pa_alen = 4;
217 }
218
219 #ifdef CONFIG_TR
220
221 void tr_setup(struct device *dev)
222 {
223 int i;
224
225
226 for (i = 0; i < DEV_NUMBUFFS; i++)
227 skb_queue_head_init(&dev->buffs[i]);
228
229 dev->hard_header = tr_header;
230 dev->rebuild_header = tr_rebuild_header;
231
232 dev->type = ARPHRD_IEEE802;
233 dev->hard_header_len = TR_HLEN;
234 dev->mtu = 2000;
235 dev->addr_len = TR_ALEN;
236 for (i = 0; i < TR_ALEN; i++) {
237 dev->broadcast[i]=0xff;
238 }
239
240
241 dev->flags = IFF_BROADCAST;
242 dev->family = AF_INET;
243 dev->pa_addr = 0;
244 dev->pa_brdaddr = 0;
245 dev->pa_mask = 0;
246 dev->pa_alen = 4;
247 }
248
249 #endif
250
251 int ether_config(struct device *dev, struct ifmap *map)
252 {
253 if (map->mem_start != (u_long)(-1))
254 dev->mem_start = map->mem_start;
255 if (map->mem_end != (u_long)(-1))
256 dev->mem_end = map->mem_end;
257 if (map->base_addr != (u_short)(-1))
258 dev->base_addr = map->base_addr;
259 if (map->irq != (u_char)(-1))
260 dev->irq = map->irq;
261 if (map->dma != (u_char)(-1))
262 dev->dma = map->dma;
263 if (map->port != (u_char)(-1))
264 dev->if_port = map->port;
265 return 0;
266 }
267
268 int register_netdev(struct device *dev)
269 {
270 struct device *d = dev_base;
271 unsigned long flags;
272 int i=MAX_ETH_CARDS;
273
274 save_flags(flags);
275 cli();
276
277 if (dev && dev->init) {
278 if (dev->name &&
279 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
280 for (i = 0; i < MAX_ETH_CARDS; ++i)
281 if (ethdev_index[i] == NULL) {
282 sprintf(dev->name, "eth%d", i);
283 printk("loading device '%s'...\n", dev->name);
284 ethdev_index[i] = dev;
285 break;
286 }
287 }
288
289 if (dev->init(dev) != 0) {
290 if (i < MAX_ETH_CARDS) ethdev_index[i] = NULL;
291 restore_flags(flags);
292 return -EIO;
293 }
294
295
296 if (dev_base) {
297 while (d->next)
298 d = d->next;
299 d->next = dev;
300 }
301 else
302 dev_base = dev;
303 dev->next = NULL;
304 }
305 restore_flags(flags);
306 return 0;
307 }
308
309 void unregister_netdev(struct device *dev)
310 {
311 struct device *d = dev_base;
312 unsigned long flags;
313 int i;
314
315 save_flags(flags);
316 cli();
317
318 if (dev == NULL)
319 {
320 printk("was NULL\n");
321 restore_flags(flags);
322 return;
323 }
324
325 if (dev->start)
326 printk("ERROR '%s' busy and not MOD_IN_USE.\n", dev->name);
327 if (dev_base == dev)
328 dev_base = dev->next;
329 else
330 {
331 while (d && (d->next != dev))
332 d = d->next;
333
334 if (d && (d->next == dev))
335 {
336 d->next = dev->next;
337 }
338 else
339 {
340 printk("unregister_netdev: '%s' not found\n", dev->name);
341 restore_flags(flags);
342 return;
343 }
344 }
345 for (i = 0; i < MAX_ETH_CARDS; ++i)
346 {
347 if (ethdev_index[i] == dev)
348 {
349 ethdev_index[i] = NULL;
350 break;
351 }
352 }
353
354
355
356
357
358
359
360 dev_close(dev);
361
362 restore_flags(flags);
363 }
364
365
366
367
368
369
370
371
372
373
374