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