This source file includes following definitions.
- mem_on
- mem_off
- e2100_probe
- e21_probe1
- e21_open
- e21_reset_8390
- e21_get_8390_hdr
- e21_block_input
- e21_block_output
- e21_close
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 static const char *version =
35 "e2100.c:v1.01 7/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
36
37 #ifdef MODULE
38 #include <linux/module.h>
39 #include <linux/version.h>
40 #endif
41
42 #include <linux/kernel.h>
43 #include <linux/sched.h>
44 #include <linux/errno.h>
45 #include <linux/string.h>
46 #include <asm/io.h>
47 #include <asm/system.h>
48 #include <linux/ioport.h>
49
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include "8390.h"
53
54 static int e21_probe_list[] = {0x300, 0x280, 0x380, 0x220, 0};
55
56
57
58
59 #define E21_NIC_OFFSET 0
60 #define E21_ASIC 0x10
61 #define E21_MEM_ENABLE 0x10
62 #define E21_MEM_ON 0x05
63 #define E21_MEM_ON_8 0x07
64 #define E21_MEM_BASE 0x11
65 #define E21_IRQ_LOW 0x12
66 #define E21_IRQ_HIGH 0x14
67 #define E21_MEDIA 0x14
68 #define E21_ALT_IFPORT 0x02
69 #define E21_BIG_MEM 0x04
70 #define E21_SAPROM 0x10
71 #define E21_IO_EXTENT 0x20
72
73 extern inline void mem_on(short port, volatile char *mem_base,
74 unsigned char start_page )
75 {
76
77
78 mem_base[start_page];
79 inb(port + E21_MEM_ENABLE);
80 outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON);
81 }
82
83 extern inline void mem_off(short port)
84 {
85 inb(port + E21_MEM_ENABLE);
86 outb(0x00, port + E21_MEM_ENABLE);
87 }
88
89
90
91
92
93 #define E21_RX_START_PG 0x00
94 #define E21_RX_STOP_PG 0x30
95 #define E21_BIG_RX_STOP_PG 0xF0
96 #define E21_TX_START_PG E21_RX_STOP_PG
97
98 int e2100_probe(struct device *dev);
99 int e21_probe1(struct device *dev, int ioaddr);
100
101 static int e21_open(struct device *dev);
102 static void e21_reset_8390(struct device *dev);
103 static void e21_block_input(struct device *dev, int count,
104 struct sk_buff *skb, int ring_offset);
105 static void e21_block_output(struct device *dev, int count,
106 const unsigned char *buf, const start_page);
107 static void e21_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
108 int ring_page);
109
110 static int e21_close(struct device *dev);
111
112
113
114
115
116
117
118
119
120 int e2100_probe(struct device *dev)
121 {
122 int *port;
123 int base_addr = dev->base_addr;
124
125 if (base_addr > 0x1ff)
126 return e21_probe1(dev, base_addr);
127 else if (base_addr != 0)
128 return ENXIO;
129
130 for (port = e21_probe_list; *port; port++) {
131 if (check_region(*port, E21_IO_EXTENT))
132 continue;
133 if (e21_probe1(dev, *port) == 0)
134 return 0;
135 }
136
137 return ENODEV;
138 }
139
140 int e21_probe1(struct device *dev, int ioaddr)
141 {
142 int i, status;
143 unsigned char *station_addr = dev->dev_addr;
144
145
146 if (inb(ioaddr + E21_SAPROM + 0) != 0x00
147 || inb(ioaddr + E21_SAPROM + 1) != 0x00
148 || inb(ioaddr + E21_SAPROM + 2) != 0x1d)
149 return ENODEV;
150
151
152 outb(E8390_NODMA + E8390_STOP, ioaddr);
153 SLOW_DOWN_IO;
154 status = inb(ioaddr);
155 if (status != 0x21 && status != 0x23)
156 return ENODEV;
157
158
159 for (i = 0; i < 6; i++)
160 station_addr[i] = inb(ioaddr + E21_SAPROM + i);
161
162 inb(ioaddr + E21_MEDIA);
163 outb(0, ioaddr + E21_ASIC);
164
165 printk("%s: E21** at %#3x,", dev->name, ioaddr);
166 for (i = 0; i < 6; i++)
167 printk(" %02X", station_addr[i]);
168
169 if (dev->irq < 2) {
170 int irqlist[] = {15,11,10,12,5,9,3,4}, i;
171 for (i = 0; i < 8; i++)
172 if (request_irq (irqlist[i], NULL, 0, "bogus") != -EBUSY) {
173 dev->irq = irqlist[i];
174 break;
175 }
176 if (i >= 8) {
177 printk(" unable to get IRQ %d.\n", dev->irq);
178 return EAGAIN;
179 }
180 } else if (dev->irq == 2)
181 dev->irq = 9;
182
183
184 request_region(ioaddr, E21_IO_EXTENT, "e2100");
185
186
187 dev->base_addr = ioaddr;
188
189 ethdev_init(dev);
190
191 ei_status.name = "E2100";
192 ei_status.word16 = 1;
193 ei_status.tx_start_page = E21_TX_START_PG;
194 ei_status.rx_start_page = E21_RX_START_PG;
195 ei_status.stop_page = E21_RX_STOP_PG;
196 ei_status.saved_irq = dev->irq;
197
198
199
200 if (dev->mem_end & 15)
201 dev->if_port = dev->mem_end & 7;
202 else {
203 dev->if_port = 0;
204 inb(ioaddr + E21_MEDIA);
205 for(i = 0; i < 6; i++)
206 if (station_addr[i] != inb(ioaddr + E21_SAPROM + 8 + i)) {
207 dev->if_port = 1;
208 break;
209 }
210 }
211
212
213
214
215 if (dev->mem_start == 0)
216 dev->mem_start = 0xd0000;
217
218 #ifdef notdef
219
220
221 dev->rmem_start = dev->mem_start + TX_PAGES*256;
222 dev->mem_end = dev->rmem_end = dev->mem_start + 2*1024;
223 #endif
224
225 printk(", IRQ %d, %s media, memory @ %#lx.\n", dev->irq,
226 dev->if_port ? "secondary" : "primary", dev->mem_start);
227
228 if (ei_debug > 0)
229 printk(version);
230
231 ei_status.reset_8390 = &e21_reset_8390;
232 ei_status.block_input = &e21_block_input;
233 ei_status.block_output = &e21_block_output;
234 ei_status.get_8390_hdr = &e21_get_8390_hdr;
235 dev->open = &e21_open;
236 dev->stop = &e21_close;
237 NS8390_init(dev, 0);
238
239 return 0;
240 }
241
242 static int
243 e21_open(struct device *dev)
244 {
245 short ioaddr = dev->base_addr;
246 int rc;
247
248 if (request_irq(dev->irq, ei_interrupt, 0, "e2100")) {
249 return EBUSY;
250 }
251 irq2dev_map[dev->irq] = dev;
252
253
254 inb(ioaddr + E21_IRQ_LOW);
255 outb(0, ioaddr + E21_ASIC + (dev->irq & 7));
256 inb(ioaddr + E21_IRQ_HIGH);
257 outb(0, ioaddr + E21_ASIC + (dev->irq > 7 ? 1:0)
258 + (dev->if_port ? E21_ALT_IFPORT : 0));
259 inb(ioaddr + E21_MEM_BASE);
260 outb(0, ioaddr + E21_ASIC + ((dev->mem_start >> 17) & 7));
261
262 rc = ei_open(dev);
263 if (rc != 0) return rc;
264 #ifdef MODULE
265 MOD_INC_USE_COUNT;
266 #endif
267 return 0;
268 }
269
270 static void
271 e21_reset_8390(struct device *dev)
272 {
273 short ioaddr = dev->base_addr;
274
275 outb(0x01, ioaddr);
276 if (ei_debug > 1) printk("resetting the E2180x3 t=%ld...", jiffies);
277 ei_status.txing = 0;
278
279
280
281 if (ei_debug > 1) printk("reset done\n");
282 return;
283 }
284
285
286
287
288 static void
289 e21_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
290 {
291
292 short ioaddr = dev->base_addr;
293 char *shared_mem = (char *)dev->mem_start;
294
295 mem_on(ioaddr, shared_mem, ring_page);
296
297 memcpy_fromio(hdr, shared_mem, sizeof(struct e8390_pkt_hdr));
298
299
300 mem_off(ioaddr);
301
302 }
303
304
305
306
307 static void
308 e21_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
309 {
310 short ioaddr = dev->base_addr;
311 char *shared_mem = (char *)dev->mem_start;
312
313 mem_on(ioaddr, shared_mem, (ring_offset>>8));
314
315
316 eth_io_copy_and_sum(skb, dev->mem_start + (ring_offset & 0xff), count, 0);
317
318 mem_off(ioaddr);
319 }
320
321 static void
322 e21_block_output(struct device *dev, int count, const unsigned char *buf,
323 int start_page)
324 {
325 short ioaddr = dev->base_addr;
326 volatile char *shared_mem = (char *)dev->mem_start;
327
328
329
330 readb(shared_mem + start_page);
331 mem_on(ioaddr, shared_mem, start_page);
332
333 memcpy_toio(shared_mem, buf, count);
334 mem_off(ioaddr);
335 }
336
337 static int
338 e21_close(struct device *dev)
339 {
340 short ioaddr = dev->base_addr;
341
342 if (ei_debug > 1)
343 printk("%s: Shutting down ethercard.\n", dev->name);
344
345 free_irq(dev->irq);
346 dev->irq = ei_status.saved_irq;
347
348
349 inb(ioaddr + E21_IRQ_LOW);
350 outb(0, ioaddr + E21_ASIC);
351 inb(ioaddr + E21_IRQ_HIGH);
352 outb(0, ioaddr + E21_ASIC);
353
354 irq2dev_map[dev->irq] = NULL;
355
356 NS8390_init(dev, 0);
357
358
359
360 mem_off(ioaddr);
361
362 #ifdef MODULE
363 MOD_DEC_USE_COUNT;
364 #endif
365
366 return 0;
367 }
368
369 #ifdef HAVE_DEVLIST
370 struct netdev_entry e21_drv =
371 {"e21", e21_probe1, E21_IO_EXTENT, e21_probe_list};
372 #endif
373
374 #ifdef MODULE
375 char kernel_version[] = UTS_RELEASE;
376 static char devicename[9] = { 0, };
377 static struct device dev_e2100 = {
378 devicename,
379 0, 0, 0, 0,
380 0, 0,
381 0, 0, 0, NULL, e2100_probe };
382
383 int io = 0x300;
384 int irq = 0;
385
386 int init_module(void)
387 {
388 if (io == 0)
389 printk("e2100: You should not use auto-probing with insmod!\n");
390 dev_e2100.base_addr = io;
391 dev_e2100.irq = irq;
392 if (register_netdev(&dev_e2100) != 0) {
393 printk("e2100: register_netdev() returned non-zero.\n");
394 return -EIO;
395 }
396 return 0;
397 }
398
399 void
400 cleanup_module(void)
401 {
402 if (MOD_IN_USE)
403 printk("e2100: device busy, remove delayed\n");
404 else
405 {
406 unregister_netdev(&dev_e2100);
407
408
409 release_region(dev_e2100.base_addr, E21_IO_EXTENT);
410 }
411 }
412 #endif
413
414
415
416
417
418
419
420
421