This source file includes following definitions.
- el2_probe
- el2_pio_probe
- el2_probe1
- el2_open
- el2_close
- el2_reset_8390
- el2_init_card
- el2_block_output
- el2_get_8390_hdr
- el2_block_input
- 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 static const char *version =
26 "3c503.c:v1.10 9/23/93 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
27
28
29 #ifdef MODULE
30 #include <linux/module.h>
31 #include <linux/version.h>
32 #endif
33
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/errno.h>
37 #include <linux/string.h>
38 #include <linux/delay.h>
39 #include <asm/io.h>
40 #include <asm/system.h>
41
42 #include <linux/netdevice.h>
43 #include <linux/etherdevice.h>
44
45 #include "8390.h"
46 #include "3c503.h"
47
48
49 int el2_probe(struct device *dev);
50 int el2_pio_probe(struct device *dev);
51 int el2_probe1(struct device *dev, int ioaddr);
52
53
54 static unsigned int netcard_portlist[] =
55 { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
56
57 #define EL2_IO_EXTENT 16
58
59 #ifdef HAVE_DEVLIST
60
61
62 struct netdev_entry el2_drv =
63 {"3c503", el2_probe, EL1_IO_EXTENT, 0};
64 struct netdev_entry el2pio_drv =
65 {"3c503pio", el2_pioprobe1, EL1_IO_EXTENT, netcard_portlist};
66 #endif
67
68 static int el2_open(struct device *dev);
69 static int el2_close(struct device *dev);
70 static void el2_reset_8390(struct device *dev);
71 static void el2_init_card(struct device *dev);
72 static void el2_block_output(struct device *dev, int count,
73 const unsigned char *buf, const start_page);
74 static void el2_block_input(struct device *dev, int count, struct sk_buff *skb,
75 int ring_offset);
76 static void el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
77 int ring_page);
78
79
80
81
82
83
84
85
86
87 int
88 el2_probe(struct device *dev)
89 {
90 int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
91 int base_addr = dev->base_addr;
92
93 if (base_addr > 0x1ff)
94 return el2_probe1(dev, base_addr);
95 else if (base_addr != 0)
96 return ENXIO;
97
98 for (addr = addrs; *addr; addr++) {
99 int i;
100 unsigned int base_bits = readb(*addr);
101
102 for(i = 7; i >= 0; i--, base_bits >>= 1)
103 if (base_bits & 0x1)
104 break;
105 if (base_bits != 1)
106 continue;
107 if (check_region(netcard_portlist[i], EL2_IO_EXTENT))
108 continue;
109 if (el2_probe1(dev, netcard_portlist[i]) == 0)
110 return 0;
111 }
112 #if ! defined(no_probe_nonshared_memory) && ! defined (HAVE_DEVLIST)
113 return el2_pio_probe(dev);
114 #else
115 return ENODEV;
116 #endif
117 }
118
119 #ifndef HAVE_DEVLIST
120
121
122 int
123 el2_pio_probe(struct device *dev)
124 {
125 int i;
126 int base_addr = dev ? dev->base_addr : 0;
127
128 if (base_addr > 0x1ff)
129 return el2_probe1(dev, base_addr);
130 else if (base_addr != 0)
131 return ENXIO;
132
133 for (i = 0; netcard_portlist[i]; i++) {
134 int ioaddr = netcard_portlist[i];
135 if (check_region(ioaddr, EL2_IO_EXTENT))
136 continue;
137 if (el2_probe1(dev, ioaddr) == 0)
138 return 0;
139 }
140
141 return ENODEV;
142 }
143 #endif
144
145
146
147
148 int
149 el2_probe1(struct device *dev, int ioaddr)
150 {
151 int i, iobase_reg, membase_reg, saved_406;
152 static unsigned version_printed = 0;
153 unsigned long vendor_id;
154
155
156 if (inb(ioaddr + 0x408) == 0xff) {
157 udelay(1000);
158 return ENODEV;
159 }
160
161
162
163 iobase_reg = inb(ioaddr+0x403);
164 membase_reg = inb(ioaddr+0x404);
165
166 if ( (iobase_reg & (iobase_reg - 1))
167 || (membase_reg & (membase_reg - 1))) {
168 return ENODEV;
169 }
170 saved_406 = inb_p(ioaddr + 0x406);
171 outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406);
172 outb_p(ECNTRL_THIN, ioaddr + 0x406);
173
174
175 outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
176 vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
177 if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
178
179 outb(saved_406, ioaddr + 0x406);
180 return ENODEV;
181 }
182
183 request_region(ioaddr, EL2_IO_EXTENT,"3c503");
184
185 if (dev == NULL)
186 dev = init_etherdev(0, sizeof(struct ei_device));
187
188 if (ei_debug && version_printed++ == 0)
189 printk(version);
190
191 dev->base_addr = ioaddr;
192 ethdev_init(dev);
193
194 printk("%s: 3c503 at %#3x,", dev->name, ioaddr);
195
196
197 for (i = 0; i < 6; i++)
198 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
199
200
201 outb(ECNTRL_THIN, ioaddr + 0x406);
202
203
204 if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg);
205 outb(EGACFR_NORM, ioaddr + 0x405);
206
207
208
209
210
211 #if defined(EI8390_THICK) || defined(EL2_AUI)
212 ei_status.interface_num = 1;
213 #else
214 ei_status.interface_num = dev->mem_end & 0xf;
215 #endif
216
217 if ((membase_reg & 0xf0) == 0) {
218 dev->mem_start = 0;
219 } else {
220 dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
221 ((membase_reg & 0xA0) ? 0x4000 : 0);
222
223 #define EL2_MEMSIZE (EL2SM_STOP_PG - EL2SM_START_PG)*256
224 #ifdef EL2MEMTEST
225
226 {
227 unsigned long mem_base = dev->mem_start;
228 unsigned int test_val = 0xbbadf00d;
229 writel(0xba5eba5e, mem_base);
230 for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
231 writel(test_val, mem_base + i);
232 if (readl(mem_base) != 0xba5eba5e
233 || readl(mem_base + i) != test_val) {
234 printk(" memory failure or memory address conflict.\n");
235 dev->mem_start = 0;
236 break;
237 }
238 test_val += 0x55555555;
239 writel(0, mem_base + i);
240 }
241 }
242 #endif
243
244
245
246 dev->mem_end = dev->rmem_end = dev->mem_start + EL2_MEMSIZE;
247 dev->rmem_start = TX_PAGES*256 + dev->mem_start;
248 }
249
250
251 ei_status.name = "3C503";
252 ei_status.tx_start_page = EL2SM_START_PG;
253 ei_status.rx_start_page = EL2SM_START_PG + TX_PAGES;
254 ei_status.stop_page = EL2SM_STOP_PG;
255 ei_status.reset_8390 = &el2_reset_8390;
256 ei_status.get_8390_hdr = &el2_get_8390_hdr;
257 ei_status.block_input = &el2_block_input;
258 ei_status.block_output = &el2_block_output;
259
260 if (dev->irq == 2)
261 dev->irq = 9;
262 else if (dev->irq > 5 && dev->irq != 9) {
263 printk("\n3c503: configured interrupt %d invalid, using autoIRQ.\n",
264 dev->irq);
265 dev->irq = 0;
266 }
267
268 ei_status.saved_irq = dev->irq;
269
270 dev->start = 0;
271 dev->open = &el2_open;
272 dev->stop = &el2_close;
273
274 if (dev->mem_start)
275 printk("\n%s: %s with shared memory at %#6lx-%#6lx.\n",
276 dev->name, ei_status.name, dev->mem_start, dev->mem_end-1);
277 else
278 printk("\n%s: %s using programmed I/O (REJUMPER for SHARED MEMORY).\n",
279 dev->name, ei_status.name);
280
281 if (ei_debug > 1)
282 printk(version);
283
284 return 0;
285 }
286
287 static int
288 el2_open(struct device *dev)
289 {
290
291 if (dev->irq < 2) {
292 int irqlist[] = {5, 9, 3, 4, 0};
293 int *irqp = irqlist;
294
295 outb(EGACFR_NORM, E33G_GACFR);
296 do {
297 if (request_irq (*irqp, NULL, 0, "bogus") != -EBUSY) {
298
299 autoirq_setup(0);
300 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
301 outb_p(0x00, E33G_IDCFR);
302 if (*irqp == autoirq_report(0)
303 && request_irq (dev->irq = *irqp, &ei_interrupt, 0, "3c503") == 0)
304 break;
305 }
306 } while (*++irqp);
307 if (*irqp == 0) {
308 outb(EGACFR_IRQOFF, E33G_GACFR);
309 return -EAGAIN;
310 }
311 } else {
312 if (request_irq(dev->irq, &ei_interrupt, 0, "3c503")) {
313 return -EAGAIN;
314 }
315 }
316 el2_init_card(dev);
317 return ei_open(dev);
318 }
319
320 static int
321 el2_close(struct device *dev)
322 {
323 free_irq(dev->irq);
324 dev->irq = ei_status.saved_irq;
325 irq2dev_map[dev->irq] = NULL;
326 outb(EGACFR_IRQOFF, E33G_GACFR);
327
328 NS8390_init(dev, 0);
329 dev->start = 0;
330
331 return 0;
332 }
333
334
335
336
337
338 static void
339 el2_reset_8390(struct device *dev)
340 {
341 if (ei_debug > 1) {
342 printk("%s: Resetting the 3c503 board...", dev->name);
343 printk("%#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
344 E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
345 }
346 outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
347 ei_status.txing = 0;
348 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
349 el2_init_card(dev);
350 if (ei_debug > 1) printk("done\n");
351 }
352
353
354 static void
355 el2_init_card(struct device *dev)
356 {
357
358 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
359
360
361
362 outb(ei_status.rx_start_page, E33G_STARTPG);
363 outb(ei_status.stop_page, E33G_STOPPG);
364
365
366 outb(0xff, E33G_VP2);
367 outb(0xff, E33G_VP1);
368 outb(0x00, E33G_VP0);
369
370 outb_p(0x00, dev->base_addr + EN0_IMR);
371
372 outb(EGACFR_NORM, E33G_GACFR);
373
374
375 outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
376 outb_p(8, E33G_DRQCNT);
377 outb_p(0x20, E33G_DMAAH);
378 outb_p(0x00, E33G_DMAAL);
379 return;
380 }
381
382
383
384 static void
385 el2_block_output(struct device *dev, int count,
386 const unsigned char *buf, const start_page)
387 {
388 int i;
389 int boguscount = 0;
390
391
392 outb(EGACFR_NORM, E33G_GACFR);
393
394 if (dev->mem_start) {
395 unsigned long dest_addr = dev->mem_start +
396 ((start_page - ei_status.tx_start_page) << 8);
397 memcpy_toio(dest_addr, buf, count);
398 return;
399 }
400
401
402 outb(0x00, E33G_DMAAL);
403 outb_p(start_page, E33G_DMAAH);
404 outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
405 | ECNTRL_START, E33G_CNTRL);
406
407
408
409
410 for(i = 0; i < count; i++) {
411 if (i % 8 == 0)
412 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
413 if (++boguscount > (i<<3) + 32) {
414 printk("%s: FIFO blocked in el2_block_output (at %d of %d, bc=%d).\n",
415 dev->name, i, count, boguscount);
416 return;
417 }
418 outb(buf[i], E33G_FIFOH);
419 }
420 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
421 return;
422 }
423
424
425 static void
426 el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
427 {
428 unsigned int i;
429 unsigned long hdr_start = dev->mem_start + ((ring_page - EL2SM_START_PG)<<8);
430
431 if (dev->mem_start) {
432 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
433 return;
434 }
435
436
437 outb(0, E33G_DMAAL);
438 outb_p(ring_page & 0xff, E33G_DMAAH);
439 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
440 | ECNTRL_START, E33G_CNTRL);
441
442
443 for(i = 0; i < sizeof(struct e8390_pkt_hdr); i++)
444 ((char *)(hdr))[i] = inb_p(E33G_FIFOH);
445
446 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
447 }
448
449
450 static void
451 el2_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
452 {
453 int boguscount = 0;
454 int end_of_ring = dev->rmem_end;
455 unsigned int i;
456
457
458 if (dev->mem_start) {
459 ring_offset -= (EL2SM_START_PG<<8);
460 if (dev->mem_start + ring_offset + count > end_of_ring) {
461
462 int semi_count = end_of_ring - (dev->mem_start + ring_offset);
463 memcpy_fromio(skb->data, dev->mem_start + ring_offset, semi_count);
464 count -= semi_count;
465 memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
466 } else {
467
468 eth_io_copy_and_sum(skb, dev->mem_start + ring_offset, count, 0);
469 }
470 return;
471 }
472
473 outb(ring_offset & 0xff, E33G_DMAAL);
474 outb_p((ring_offset >> 8) & 0xff, E33G_DMAAH);
475 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
476 | ECNTRL_START, E33G_CNTRL);
477
478
479
480 for(i = 0; i < count; i++) {
481 if (i % 8 == 0)
482 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
483 if (++boguscount > (i<<3) + 32) {
484 printk("%s: FIFO blocked in el2_block_input() (at %d of %d, bc=%d).\n",
485 dev->name, i, count, boguscount);
486 boguscount = 0;
487 break;
488 }
489 (skb->data)[i] = inb_p(E33G_FIFOH);
490 }
491 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
492 }
493 #ifdef MODULE
494 char kernel_version[] = UTS_RELEASE;
495 static struct device el2_drv =
496 {"3c503", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, el2_probe };
497
498 static struct device el2pio_drv =
499 {"3c503pio", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, el2_pio_probe };
500
501 int io = 0x300;
502 int irq = 0;
503
504 static int no_pio = 1;
505 int init_module(void)
506 {
507 int rc1, rc2;
508 el2_drv.base_addr = io;
509 el2_drv.irq = irq;
510 el2pio_drv.base_addr = io;
511 el2pio_drv.irq = irq;
512
513 if (io == 0)
514 printk("3c503: You should not use auto-probing with insmod!\n");
515
516 rc2 = 0;
517 no_pio = 1;
518 rc1 = register_netdev(&el2_drv);
519 if (rc1 != 0) {
520 rc2 = register_netdev(&el2pio_drv);
521 no_pio = 0;
522 }
523
524 if (rc1 != 0 && rc2 != 0)
525 return -EIO;
526 return 0;
527 }
528
529 void
530 cleanup_module(void)
531 {
532 if (MOD_IN_USE)
533 printk("3c503: device busy, remove delayed\n");
534 else {
535 int ioaddr;
536
537 if (no_pio) {
538 ioaddr = el2_drv.base_addr;
539 unregister_netdev(&el2_drv);
540 } else {
541 ioaddr = el2pio_drv.base_addr;
542 unregister_netdev(&el2pio_drv);
543 }
544
545
546 release_region(ioaddr, EL2_IO_EXTENT);
547
548 }
549 }
550 #endif
551
552
553
554
555
556
557
558