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
21
22
23 #include <linux/config.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/types.h>
27 #include <linux/fs.h>
28 #include <linux/malloc.h>
29 #include <linux/if_ether.h>
30 #include <linux/string.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
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
56
57
58
59
60
61
62 unsigned long net_dev_init (unsigned long mem_start, unsigned long mem_end)
63 {
64
65 #if defined(CONFIG_LANCE)
66 mem_start = lance_init(mem_start, mem_end);
67 #endif
68 #if defined(CONFIG_PI)
69 mem_start = pi_init(mem_start, mem_end);
70 #endif
71 return mem_start;
72 }
73
74
75
76
77
78
79
80
81
82
83
84 struct device *
85 init_etherdev(struct device *dev, int sizeof_private, unsigned long *mem_startp)
86 {
87 int new_device = 0;
88 int i;
89
90 if (dev == NULL) {
91 int alloc_size = sizeof(struct device) + sizeof("eth%d ")
92 + sizeof_private;
93 if (mem_startp && *mem_startp ) {
94 dev = (struct device *)*mem_startp;
95 *mem_startp += alloc_size;
96 } else
97 dev = (struct device *)kmalloc(alloc_size, GFP_KERNEL);
98 memset(dev, 0, sizeof(alloc_size));
99 dev->name = (char *)(dev + 1);
100 if (sizeof_private)
101 dev->priv = dev->name + sizeof("eth%d ");
102 new_device = 1;
103 }
104
105 if (dev->name &&
106 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
107 for (i = 0; i < MAX_ETH_CARDS; ++i)
108 if (ethdev_index[i] == NULL) {
109 sprintf(dev->name, "eth%d", i);
110 ethdev_index[i] = dev;
111 break;
112 }
113 }
114
115 ether_setup(dev);
116
117 if (new_device) {
118
119 struct device **old_devp = &dev_base;
120 while ((*old_devp)->next)
121 old_devp = & (*old_devp)->next;
122 (*old_devp)->next = dev;
123 dev->next = 0;
124 }
125 return dev;
126 }
127
128 void ether_setup(struct device *dev)
129 {
130 int i;
131
132
133 for (i = 0; i < DEV_NUMBUFFS; i++)
134 skb_queue_head_init(&dev->buffs[i]);
135
136
137 if (dev->name && (strncmp(dev->name, "eth", 3) == 0)) {
138 i = simple_strtoul(dev->name + 3, NULL, 0);
139 if (ethdev_index[i] == NULL) {
140 ethdev_index[i] = dev;
141 }
142 else if (dev != ethdev_index[i]) {
143
144 printk("ether_setup: Ouch! Someone else took %s\n",
145 dev->name);
146 }
147 }
148
149 dev->hard_header = eth_header;
150 dev->rebuild_header = eth_rebuild_header;
151 dev->type_trans = eth_type_trans;
152
153 dev->type = ARPHRD_ETHER;
154 dev->hard_header_len = ETH_HLEN;
155 dev->mtu = 1500;
156 dev->addr_len = ETH_ALEN;
157 for (i = 0; i < ETH_ALEN; i++) {
158 dev->broadcast[i]=0xff;
159 }
160
161
162 dev->flags = IFF_BROADCAST;
163 dev->family = AF_INET;
164 dev->pa_addr = 0;
165 dev->pa_brdaddr = 0;
166 dev->pa_mask = 0;
167 dev->pa_alen = sizeof(unsigned long);
168 }
169
170 int ether_config(struct device *dev, struct ifmap *map)
171 {
172 if (map->mem_start != (u_long)(-1))
173 dev->mem_start = map->mem_start;
174 if (map->mem_end != (u_long)(-1))
175 dev->mem_end = map->mem_end;
176 if (map->base_addr != (u_short)(-1))
177 dev->base_addr = map->base_addr;
178 if (map->irq != (u_char)(-1))
179 dev->irq = map->irq;
180 if (map->dma != (u_char)(-1))
181 dev->dma = map->dma;
182 if (map->port != (u_char)(-1))
183 dev->if_port = map->port;
184 return 0;
185 }
186
187 int register_netdev(struct device *dev)
188 {
189 struct device *d = dev_base;
190 unsigned long flags;
191 int i;
192
193 save_flags(flags);
194 cli();
195
196 if (dev && dev->init) {
197 if (dev->init(dev) != 0) {
198 restore_flags(flags);
199 return -EIO;
200 }
201
202 if (dev->name &&
203 ((dev->name[0] == '\0') || (dev->name[0] == ' '))) {
204 for (i = 0; i < MAX_ETH_CARDS; ++i)
205 if (ethdev_index[i] == NULL) {
206 sprintf(dev->name, "eth%d", i);
207 printk("device '%s' loaded\n", dev->name);
208 ethdev_index[i] = dev;
209 break;
210 }
211 }
212
213
214 if (dev_base) {
215 while (d->next)
216 d = d->next;
217 d->next = dev;
218 }
219 else
220 dev_base = dev;
221 dev->next = NULL;
222 }
223 restore_flags(flags);
224 return 0;
225 }
226
227 void unregister_netdev(struct device *dev)
228 {
229 struct device *d = dev_base;
230 unsigned long flags;
231 int i;
232
233 save_flags(flags);
234 cli();
235
236 printk("unregister_netdev: device ");
237
238 if (dev == NULL) {
239 printk("was NULL\n");
240 restore_flags(flags);
241 return;
242 }
243
244 if (dev->start)
245 printk("'%s' busy\n", dev->name);
246 else {
247 if (dev_base == dev)
248 dev_base = dev->next;
249 else {
250 while (d && (d->next != dev))
251 d = d->next;
252
253 if (d && (d->next == dev)) {
254 d->next = dev->next;
255 printk("'%s' unlinked\n", dev->name);
256 }
257 else {
258 printk("'%s' not found\n", dev->name);
259 restore_flags(flags);
260 return;
261 }
262 }
263 for (i = 0; i < MAX_ETH_CARDS; ++i) {
264 if (ethdev_index[i] == dev) {
265 ethdev_index[i] = NULL;
266 break;
267 }
268 }
269 }
270 restore_flags(flags);
271 }
272
273
274
275
276
277
278
279
280
281
282