This source file includes following definitions.
- de4x5_probe
- de4x5_hw_init
- de4x5_open
- de4x5_init
- de4x5_queue_pkt
- de4x5_interrupt
- de4x5_rx
- de4x5_tx
- de4x5_close
- de4x5_get_stats
- load_packet
- set_multicast_list
- SetMulticastFilter
- eisa_probe
- pci_probe
- alloc_device
- autoconf_media
- create_packet
- dce_get_ticks
- dce_us_delay
- dce_ms_delay
- EISA_signature
- DevicePresent
- aprom_crc
- de4x5_ioctl
- 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 static char *version = "de4x5.c:v0.22 2/10/95 davies@wanton.lkg.dec.com\n";
124
125 #include <linux/config.h>
126 #ifdef MODULE
127 #include <linux/module.h>
128 #include <linux/version.h>
129 #else
130 #define MOD_INC_USE_COUNT
131 #define MOD_DEC_USE_COUNT
132 #endif
133
134 #include <linux/kernel.h>
135 #include <linux/sched.h>
136 #include <linux/string.h>
137 #include <linux/interrupt.h>
138 #include <linux/ptrace.h>
139 #include <linux/errno.h>
140 #include <linux/ioport.h>
141 #include <linux/malloc.h>
142 #include <linux/pci.h>
143 #include <asm/bitops.h>
144 #include <asm/io.h>
145 #include <asm/dma.h>
146 #include <asm/segment.h>
147
148 #include <linux/netdevice.h>
149 #include <linux/etherdevice.h>
150 #include <linux/skbuff.h>
151
152 #include <linux/time.h>
153 #include <linux/types.h>
154 #include <linux/unistd.h>
155
156 #include "de4x5.h"
157
158 #ifdef DE4X5_DEBUG
159 static int de4x5_debug = DE4X5_DEBUG;
160 #else
161 static int de4x5_debug = 1;
162 #endif
163
164
165
166
167 #define PROBE_LENGTH 32
168 #define ETH_PROM_SIG 0xAA5500FFUL
169
170
171
172
173 #define PKT_BUF_SZ 1544
174 #define MAX_PKT_SZ 1514
175 #define MAX_DAT_SZ 1500
176 #define MIN_DAT_SZ 1
177 #define PKT_HDR_LEN 14
178
179 #define CRC_POLYNOMIAL_BE 0x04c11db7UL
180 #define CRC_POLYNOMIAL_LE 0xedb88320UL
181
182
183
184
185 #define DE4X5_EISA_IO_PORTS 0x0c00
186 #define DE4X5_EISA_TOTAL_SIZE 0xfff
187
188 #define MAX_EISA_SLOTS 16
189 #define EISA_SLOT_INC 0x1000
190
191 #define DE4X5_SIGNATURE {"DE425",""}
192 #define DE4X5_NAME_LENGTH 8
193
194
195
196
197 #define PCI_MAX_BUS_NUM 8
198 #define DE4X5_PCI_TOTAL_SIZE 0x80
199
200
201
202
203 #define TIMER_WIDTH 16
204 #define TIMER_PORT 0x43
205 #define TIMER_LATCH 0x06
206 #define TIMER_READ 0x40
207 #define TIMER_TICK 419
208 #define DELAY_QUANT 5
209
210 #define LWPAD ((long)(sizeof(long) - 1))
211
212 #ifndef IS_ZYNX
213 static int is_zynx = 0;
214 #else
215 static int is_zynx = 1;
216 #endif
217
218
219
220
221 static u_long irq_mask = IMR_RIM | IMR_TIM | IMR_TUM ;
222
223 static u_long irq_en = IMR_NIM | IMR_AIM;
224
225 #define ENABLE_IRQs \
226 imr |= irq_en;\
227 outl(imr, DE4X5_IMR)
228
229 #define DISABLE_IRQs \
230 imr = inl(DE4X5_IMR);\
231 imr &= ~irq_en;\
232 outl(imr, DE4X5_IMR)
233
234 #define UNMASK_IRQs \
235 imr |= irq_mask;\
236 outl(imr, DE4X5_IMR)
237
238 #define MASK_IRQs \
239 imr = inl(DE4X5_IMR);\
240 imr &= ~irq_mask;\
241 outl(imr, DE4X5_IMR)
242
243
244
245
246 #define START_DE4X5 \
247 omr = inl(DE4X5_OMR);\
248 omr |= OMR_ST | OMR_SR;\
249 outl(omr, DE4X5_OMR)
250
251 #define STOP_DE4X5 \
252 omr = inl(DE4X5_OMR);\
253 omr &= ~(OMR_ST|OMR_SR);\
254 outl(omr, DE4X5_OMR)
255
256
257
258
259 #define RESET_SIA \
260 outl(SICR_RESET, DE4X5_SICR); \
261 outl(STRR_RESET, DE4X5_STRR); \
262 outl(SIGR_RESET, DE4X5_SIGR)
263
264
265
266
267
268
269
270 #define NUM_RX_DESC 64
271 #define NUM_TX_DESC 8
272 #define BUFF_ALLOC_RETRIES 10
273 #define RX_BUFF_SZ 256
274
275
276 struct de4x5_desc {
277 volatile long status;
278 u_long des1;
279 char *buf;
280 char *next;
281 };
282
283
284
285
286 #define DE4X5_PKT_STAT_SZ 16
287 #define DE4X5_PKT_BIN_SZ 128
288
289
290 struct de4x5_private {
291 char adapter_name[80];
292 struct de4x5_desc rx_ring[NUM_RX_DESC];
293 struct de4x5_desc tx_ring[NUM_TX_DESC];
294 struct sk_buff *skb[NUM_TX_DESC];
295 int rx_new, rx_old;
296 int tx_new, tx_old;
297 char setup_frame[SETUP_FRAME_LEN];
298 struct enet_statistics stats;
299 struct {
300 unsigned long bins[DE4X5_PKT_STAT_SZ];
301 unsigned long unicast;
302 unsigned long multicast;
303 unsigned long broadcast;
304 unsigned long excessive_collisions;
305 unsigned long tx_underruns;
306 unsigned long excessive_underruns;
307 } pktStats;
308 char rxRingSize;
309 char txRingSize;
310 char bus;
311 char lostMedia;
312 };
313
314 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
315 lp->tx_old+lp->txRingSize-lp->tx_new-1:\
316 lp->tx_old -lp->tx_new-1)
317 #define TX_SUSPENDED (((sts & STS_TS) ^ TS_SUSP)==0)
318
319
320
321
322 static int de4x5_open(struct device *dev);
323 static int de4x5_queue_pkt(struct sk_buff *skb, struct device *dev);
324 static void de4x5_interrupt(int irq, struct pt_regs * regs);
325 static int de4x5_close(struct device *dev);
326 static struct enet_statistics *de4x5_get_stats(struct device *dev);
327 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
328 static int de4x5_ioctl(struct device *dev, struct ifreq *rq, int cmd);
329
330
331
332
333 static int de4x5_hw_init(struct device *dev, short iobase);
334 static int de4x5_init(struct device *dev);
335 static int de4x5_rx(struct device *dev);
336 static int de4x5_tx(struct device *dev);
337
338 static int autoconf_media(struct device *dev);
339 static void create_packet(struct device *dev, char *frame, int len);
340 static u_short dce_get_ticks(void);
341 static void dce_us_delay(u_long usec);
342 static void dce_ms_delay(u_long msec);
343 static void load_packet(struct device *dev, char *buf, u_long flags, struct sk_buff *skb);
344 static void EISA_signature(char * name, short iobase);
345 static int DevicePresent(short iobase);
346 static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs, char *multicast_table);
347
348 static int aprom_crc (struct device *dev);
349
350 static void eisa_probe(struct device *dev, short iobase);
351 static void pci_probe(struct device *dev, short iobase);
352 static struct device *alloc_device(struct device *dev, int iobase);
353
354 #ifdef MODULE
355 int init_module(void);
356 void cleanup_module(void);
357 static int autoprobed = 1, loading_module = 1;
358 # else
359 static unsigned char de4x5_irq[] = {5,9,10,11};
360 static int autoprobed = 0, loading_module = 0;
361 #endif
362
363 static char name[DE4X5_NAME_LENGTH + 1];
364 static int num_de4x5s = 0, num_eth = 0;
365
366
367
368
369
370
371 static struct bus_type {
372 int bus;
373 int device;
374 } bus;
375
376
377
378
379 #define RESET_DE4X5 {\
380 long i;\
381 i=inl(DE4X5_BMR);\
382 outl(i | BMR_SWR, DE4X5_BMR);\
383 outl(i, DE4X5_BMR);\
384 for (i=0;i<5;i++) inl(DE4X5_BMR);\
385 }
386
387
388
389
390 int de4x5_probe(struct device *dev)
391 {
392 int tmp = num_de4x5s, iobase = dev->base_addr;
393 int status = -ENODEV;
394
395 if ((iobase == 0) && loading_module){
396 printk("Autoprobing is not supported when loading a module based driver.\n");
397 status = -EIO;
398 } else {
399
400 eisa_probe(dev, iobase);
401 pci_probe(dev, iobase);
402
403 if ((tmp == num_de4x5s) && (iobase != 0)) {
404 printk("%s: de4x5_probe() cannot find device at 0x%04x.\n", dev->name,
405 iobase);
406 }
407
408
409
410
411
412 for (; dev->priv == NULL && dev->next != NULL; dev = dev->next);
413
414 if (dev->priv) status = 0;
415 if (iobase == 0) autoprobed = 1;
416 }
417
418 return status;
419 }
420
421 static int
422 de4x5_hw_init(struct device *dev, short iobase)
423 {
424 struct bus_type *lp = &bus;
425 int tmpbus, i, j, status=0;
426 char *tmp;
427 u_long nicsr;
428
429 RESET_DE4X5;
430
431 if (((nicsr=inl(DE4X5_STS)) & (STS_TS | STS_RS)) == 0) {
432
433
434
435 if (lp->bus == PCI) {
436 if (!is_zynx) {
437 strcpy(name, "DE435");
438 } else {
439 strcpy(name, "ZYNX");
440 }
441 } else {
442 EISA_signature(name, EISA_ID0);
443 }
444
445 if (*name != '\0') {
446 dev->base_addr = iobase;
447 request_region(iobase, (lp->bus == PCI ? DE4X5_PCI_TOTAL_SIZE :
448 DE4X5_EISA_TOTAL_SIZE), name);
449
450 if (lp->bus == EISA) {
451 printk("%s: %s at %#3x (EISA slot %d)",
452 dev->name, name, (u_short)iobase, (((u_short)iobase>>12)&0x0f));
453 } else {
454 printk("%s: %s at %#3x (PCI device %d)", dev->name, name, (u_short)iobase,lp->device);
455 }
456
457 printk(", h/w address ");
458 status = aprom_crc(dev);
459 for (i = 0; i < ETH_ALEN - 1; i++) {
460 printk("%2.2x:", dev->dev_addr[i]);
461 }
462 printk("%2.2x,\n", dev->dev_addr[i]);
463
464 tmpbus = lp->bus;
465
466 if (status == 0) {
467 struct de4x5_private *lp;
468
469
470
471
472
473 dev->priv = (void *) kmalloc(sizeof(struct de4x5_private) + LWPAD,
474 GFP_KERNEL);
475
476
477
478 dev->priv = (void *)(((u_long)dev->priv + LWPAD) & ~LWPAD);
479 lp = (struct de4x5_private *)dev->priv;
480 memset(dev->priv, 0, sizeof(struct de4x5_private));
481 lp->bus = tmpbus;
482 strcpy(lp->adapter_name, name);
483
484
485
486
487
488
489 for (tmp=NULL, j=0; j<BUFF_ALLOC_RETRIES && tmp==NULL; j++) {
490 if ((tmp = (void *)kmalloc(RX_BUFF_SZ * NUM_RX_DESC + LWPAD,
491 GFP_KERNEL)) != NULL) {
492 tmp = (void *)(((u_long) tmp + LWPAD) & ~LWPAD);
493 for (i=0; i<NUM_RX_DESC; i++) {
494 lp->rx_ring[i].status = 0;
495 lp->rx_ring[i].des1 = RX_BUFF_SZ;
496 lp->rx_ring[i].buf = tmp + i * RX_BUFF_SZ;
497 lp->rx_ring[i].next = NULL;
498 }
499 }
500 }
501
502 if (tmp != NULL) {
503 lp->rxRingSize = NUM_RX_DESC;
504 lp->txRingSize = NUM_TX_DESC;
505
506
507 lp->rx_ring[lp->rxRingSize - 1].des1 |= RD_RER;
508 lp->tx_ring[lp->txRingSize - 1].des1 |= TD_TER;
509
510
511 outl((u_long)lp->rx_ring, DE4X5_RRBA);
512 outl((u_long)lp->tx_ring, DE4X5_TRBA);
513
514 if (dev->irq < 2) {
515 #ifndef MODULE
516 unsigned char irqnum;
517 u_long omr;
518 autoirq_setup(0);
519
520 omr = inl(DE4X5_OMR);
521 outl(IMR_AIM|IMR_RUM, DE4X5_IMR);
522 outl(OMR_SR | omr, DE4X5_OMR);
523
524 irqnum = autoirq_report(1);
525 if (!irqnum) {
526 printk(" and failed to detect IRQ line.\n");
527 status = -ENXIO;
528 } else {
529 for (dev->irq=0,i=0; i<sizeof(de4x5_irq) && !dev->irq; i++) {
530 if (irqnum == de4x5_irq[i]) {
531 dev->irq = irqnum;
532 printk(" and uses IRQ%d.\n", dev->irq);
533 }
534 }
535
536 if (!dev->irq) {
537 printk(" but incorrect IRQ line detected.\n");
538 status = -ENXIO;
539 }
540 }
541
542 outl(0, DE4X5_IMR);
543
544 #endif
545 } else {
546 printk(" and requires IRQ%d (not probed).\n", dev->irq);
547 }
548 } else {
549 printk("%s: Kernel could not allocate RX buffer memory.\n",
550 dev->name);
551 status = -ENXIO;
552 }
553 } else {
554 printk(" which has an Ethernet PROM CRC error.\n");
555 status = -ENXIO;
556 }
557 if (status) release_region(iobase, (lp->bus == PCI ?
558 DE4X5_PCI_TOTAL_SIZE :
559 DE4X5_EISA_TOTAL_SIZE));
560 } else {
561 status = -ENXIO;
562 }
563 } else {
564 status = -ENXIO;
565 }
566
567 if (!status) {
568 if (de4x5_debug > 0) {
569 printk(version);
570 }
571
572
573 dev->open = &de4x5_open;
574 dev->hard_start_xmit = &de4x5_queue_pkt;
575 dev->stop = &de4x5_close;
576 dev->get_stats = &de4x5_get_stats;
577 #ifdef HAVE_MULTICAST
578 dev->set_multicast_list = &set_multicast_list;
579 #endif
580 dev->do_ioctl = &de4x5_ioctl;
581
582 dev->mem_start = 0;
583
584
585 ether_setup(dev);
586 } else {
587 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
588 if (lp) {
589 kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + LWPAD);
590 }
591 if (dev->priv) {
592 kfree_s(dev->priv, sizeof(struct de4x5_private) + LWPAD);
593 dev->priv = NULL;
594 }
595 }
596
597 return status;
598 }
599
600
601 static int
602 de4x5_open(struct device *dev)
603 {
604 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
605 short iobase = dev->base_addr;
606 int i, status = 0;
607 u_long imr, omr, sts;
608
609
610
611
612 STOP_DE4X5;
613
614 if (request_irq(dev->irq, (void *)de4x5_interrupt, 0, lp->adapter_name)) {
615 printk("de4x5_open(): Requested IRQ%d is busy\n",dev->irq);
616 status = -EAGAIN;
617 } else {
618
619 irq2dev_map[dev->irq] = dev;
620
621
622
623 status = de4x5_init(dev);
624
625 if (de4x5_debug > 1){
626 printk("%s: de4x5 open with irq %d\n",dev->name,dev->irq);
627 printk("\tphysical address: ");
628 for (i=0;i<6;i++){
629 printk("%2.2x:",(short)dev->dev_addr[i]);
630 }
631 printk("\n");
632 printk("Descriptor head addresses:\n");
633 printk("\t0x%8.8lx 0x%8.8lx\n",(long)lp->rx_ring,(long)lp->tx_ring);
634 printk("Descriptor addresses:\nRX: ");
635 for (i=0;i<lp->rxRingSize-1;i++){
636 if (i < 3) {
637 printk("0x%8.8lx ",(long)&lp->rx_ring[i].status);
638 }
639 }
640 printk("...0x%8.8lx\n",(long)&lp->rx_ring[i].status);
641 printk("TX: ");
642 for (i=0;i<lp->txRingSize-1;i++){
643 if (i < 3) {
644 printk("0x%8.8lx ", (long)&lp->tx_ring[i].status);
645 }
646 }
647 printk("...0x%8.8lx\n", (long)&lp->tx_ring[i].status);
648 printk("Descriptor buffers:\nRX: ");
649 for (i=0;i<lp->rxRingSize-1;i++){
650 if (i < 3) {
651 printk("0x%8.8lx ",(long)lp->rx_ring[i].buf);
652 }
653 }
654 printk("...0x%8.8lx\n",(long)lp->rx_ring[i].buf);
655 printk("TX: ");
656 for (i=0;i<lp->txRingSize-1;i++){
657 if (i < 3) {
658 printk("0x%8.8lx ", (long)lp->tx_ring[i].buf);
659 }
660 }
661 printk("...0x%8.8lx\n", (long)lp->tx_ring[i].buf);
662 printk("Ring size: \nRX: %d\nTX: %d\n",
663 (short)lp->rxRingSize,
664 (short)lp->txRingSize);
665 printk("\tstatus: %d\n", status);
666 }
667
668 if (!status) {
669 dev->tbusy = 0;
670 dev->start = 1;
671 dev->interrupt = UNMASK_INTERRUPTS;
672
673
674
675
676 sts = inl(DE4X5_STS);
677 outl(sts, DE4X5_STS);
678
679
680
681
682 imr = 0;
683 UNMASK_IRQs;
684 ENABLE_IRQs;
685
686 START_DE4X5;
687 }
688 if (de4x5_debug > 1) {
689 printk("\tsts: 0x%08x\n", inl(DE4X5_STS));
690 printk("\tbmr: 0x%08x\n", inl(DE4X5_BMR));
691 printk("\timr: 0x%08x\n", inl(DE4X5_IMR));
692 printk("\tomr: 0x%08x\n", inl(DE4X5_OMR));
693 printk("\tsisr: 0x%08x\n", inl(DE4X5_SISR));
694 printk("\tsicr: 0x%08x\n", inl(DE4X5_SICR));
695 printk("\tstrr: 0x%08x\n", inl(DE4X5_STRR));
696 printk("\tsigr: 0x%08x\n", inl(DE4X5_SIGR));
697 }
698 }
699
700 MOD_INC_USE_COUNT;
701
702 return status;
703 }
704
705
706
707
708 static int
709 de4x5_init(struct device *dev)
710 {
711 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
712 short iobase = dev->base_addr;
713 int offset, status = 0;
714 u_long i, j, bmr, omr;
715 char *pa;
716
717
718 RESET_DE4X5;
719
720
721 bmr = inl(DE4X5_BMR);
722 bmr |= TAP_1_6MS | CAL_16LONG;
723 outl(bmr, DE4X5_BMR);
724
725
726 omr = OMR_HP;
727 offset = IMPERF_PA_OFFSET;
728
729
730 set_bit(0, (void *)&dev->tbusy);
731
732
733 outl((u_long)lp->rx_ring, DE4X5_RRBA);
734 outl((u_long)lp->tx_ring, DE4X5_TRBA);
735
736
737 lp->rx_new = lp->rx_old = 0;
738 lp->tx_new = lp->tx_old = 0;
739
740
741 for (i = 0; i < lp->rxRingSize; i++) {
742 lp->rx_ring[i].status = R_OWN;
743 }
744
745
746 for (i = 0; i < lp->txRingSize; i++) {
747 lp->tx_ring[i].status = 0;
748 }
749
750
751 memset(lp->setup_frame, 0, SETUP_FRAME_LEN);
752
753
754 for (pa=lp->setup_frame+offset, j=0; j<ETH_ALEN; j++) {
755 *(pa + j) = dev->dev_addr[j];
756 if (j & 0x01) pa += 2;
757 }
758
759
760 set_multicast_list(dev, 0, NULL);
761
762
763 load_packet(dev, lp->setup_frame, HASH_F | TD_SET | SETUP_FRAME_LEN, NULL);
764
765
766 outl(omr|OMR_ST, DE4X5_OMR);
767
768
769 for (j=0, i=0;i<100 && j==0;i++) {
770 if (lp->tx_ring[lp->tx_new].status >= 0) j=1;
771 }
772 outl(omr, DE4X5_OMR);
773
774 if (i == 100) {
775 printk("%s: Setup frame timed out, status %08x\n", dev->name,
776 inl(DE4X5_STS));
777 status = -EIO;
778 }
779
780
781 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
782 lp->tx_old = lp->tx_new;
783
784
785 if (autoconf_media(dev) == 0) {
786 status = -EIO;
787 }
788
789 return 0;
790 }
791
792
793
794
795 static int
796 de4x5_queue_pkt(struct sk_buff *skb, struct device *dev)
797 {
798 volatile struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
799 int iobase = dev->base_addr;
800 int status = 0;
801 u_long imr, omr, sts;
802
803 sts = inl(DE4X5_STS);
804
805
806
807
808
809
810 if (dev->tbusy || (lp->lostMedia > 3)) {
811 int tickssofar = jiffies - dev->trans_start;
812 if (tickssofar < 10 && !lp->lostMedia) {
813
814 if ((TX_BUFFS_AVAIL > 0) && dev->tbusy) {
815 dev->tbusy = 0;
816 }
817 status = -1;
818 } else {
819 printk("%s: transmit timed out, status %08x, tbusy:%d, lostMedia:%d tickssofar:%d, resetting.\n",dev->name, inl(DE4X5_STS), dev->tbusy, lp->lostMedia, tickssofar);
820
821
822 STOP_DE4X5;
823 status = de4x5_init(dev);
824
825
826 if (!status) {
827
828 dev->trans_start = jiffies;
829 START_DE4X5;
830
831
832 sts = inl(DE4X5_STS);
833 outl(sts, DE4X5_STS);
834
835
836 imr = 0;
837 UNMASK_IRQs;
838
839 dev->interrupt = UNMASK_INTERRUPTS;
840 dev->start = 1;
841 dev->tbusy = 0;
842
843 ENABLE_IRQs;
844 } else {
845 printk("%s: hardware initialisation failure, status %08x.\n",
846 dev->name, inl(DE4X5_STS));
847 }
848 }
849 } else if (skb == NULL) {
850 dev_tint(dev);
851 } else if (skb->len > 0) {
852
853
854
855
856
857 if (set_bit(0, (void*)&dev->tbusy) != 0)
858 printk("%s: Transmitter access conflict.\n", dev->name);
859
860 if (TX_BUFFS_AVAIL > 0) {
861 if (((u_long)skb->data & ~0x03) != (u_long)skb->data) {
862 printk("%s: TX skb buffer alignment prob..\n", dev->name);
863 }
864
865 load_packet(dev, skb->data, TD_IC | TD_LS | TD_FS | skb->len, skb);
866 outl(POLL_DEMAND, DE4X5_TPD);
867
868 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
869
870 dev->trans_start = jiffies;
871 }
872
873 if (TX_BUFFS_AVAIL > 0) {
874 dev->tbusy = 0;
875 }
876 }
877
878 return status;
879 }
880
881
882
883
884 static void
885 de4x5_interrupt(int irq, struct pt_regs * regs)
886 {
887 struct device *dev = (struct device *)(irq2dev_map[irq]);
888 struct de4x5_private *lp;
889 int iobase;
890 u_long imr, sts;
891
892 if (dev == NULL) {
893 printk ("de4x5_interrupt(): irq %d for unknown device.\n", irq);
894 } else {
895 lp = (struct de4x5_private *)dev->priv;
896 iobase = dev->base_addr;
897
898 if (dev->interrupt)
899 printk("%s: Re-entering the interrupt handler.\n", dev->name);
900
901 dev->interrupt = MASK_INTERRUPTS;
902
903
904
905
906
907
908
909 sts = inl(DE4X5_STS);
910 MASK_IRQs;
911
912
913
914
915 outl(sts, DE4X5_STS);
916
917 if (sts & STS_RI)
918 de4x5_rx(dev);
919
920 if (sts & STS_TI)
921 de4x5_tx(dev);
922
923 if ((TX_BUFFS_AVAIL > 0) && dev->tbusy) {
924 dev->tbusy = 0;
925 mark_bh(NET_BH);
926 }
927
928 dev->interrupt = UNMASK_INTERRUPTS;
929
930 UNMASK_IRQs;
931 }
932
933 return;
934 }
935
936 static int
937 de4x5_rx(struct device *dev)
938 {
939 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
940 int i, entry;
941 volatile long status;
942 char *buf;
943
944
945 for (entry = lp->rx_new; lp->rx_ring[entry].status >= 0;entry = lp->rx_new) {
946 status = lp->rx_ring[entry].status;
947
948 if (status & RD_FS) {
949 lp->rx_old = entry;
950 }
951
952 if (status & RD_LS) {
953 if (status & RD_ES) {
954 lp->stats.rx_errors++;
955 if (status & (RD_RF | RD_TL)) lp->stats.rx_frame_errors++;
956 if (status & RD_CE) lp->stats.rx_crc_errors++;
957 if (status & RD_OF) lp->stats.rx_fifo_errors++;
958 } else {
959 struct sk_buff *skb;
960 short pkt_len = (short)(lp->rx_ring[entry].status >> 16);
961
962 if ((skb = alloc_skb(pkt_len, GFP_ATOMIC)) != NULL) {
963 skb->len = pkt_len;
964 skb->dev = dev;
965
966 if (entry < lp->rx_old) {
967 short len = (lp->rxRingSize - lp->rx_old) * RX_BUFF_SZ;
968 memcpy(skb->data, lp->rx_ring[lp->rx_old].buf, len);
969 memcpy(skb->data + len, lp->rx_ring[0].buf, pkt_len - len);
970 } else {
971 memcpy(skb->data, lp->rx_ring[lp->rx_old].buf, pkt_len);
972 }
973
974
975
976
977
978 netif_rx(skb);
979
980
981
982
983 lp->stats.rx_packets++;
984 for (i=1; i<DE4X5_PKT_STAT_SZ-1; i++) {
985 if (pkt_len < i*DE4X5_PKT_BIN_SZ) {
986 lp->pktStats.bins[i]++;
987 i = DE4X5_PKT_STAT_SZ;
988 }
989 }
990 buf = skb->data;
991 if (buf[0] & 0x01) {
992 if ((*(long *)&buf[0] == -1) && (*(short *)&buf[4] == -1)) {
993 lp->pktStats.broadcast++;
994 } else {
995 lp->pktStats.multicast++;
996 }
997 } else if ((*(long *)&buf[0] == *(long *)&dev->dev_addr[0]) &&
998 (*(short *)&buf[4] == *(short *)&dev->dev_addr[4])) {
999 lp->pktStats.unicast++;
1000 }
1001
1002 lp->pktStats.bins[0]++;
1003 if (lp->pktStats.bins[0] == 0) {
1004 memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
1005 }
1006 } else {
1007 printk("%s: Insufficient memory; nuking packet.\n", dev->name);
1008 lp->stats.rx_dropped++;
1009 break;
1010 }
1011 }
1012
1013
1014 for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)%lp->rxRingSize) {
1015 lp->rx_ring[lp->rx_old].status = R_OWN;
1016 }
1017 lp->rx_ring[entry].status = R_OWN;
1018 }
1019
1020
1021
1022
1023 lp->rx_new = (++lp->rx_new) % lp->rxRingSize;
1024 }
1025
1026 return 0;
1027 }
1028
1029
1030
1031
1032 static int
1033 de4x5_tx(struct device *dev)
1034 {
1035 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1036 int entry, iobase = dev->base_addr;
1037 volatile long status;
1038
1039 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1040 status = lp->tx_ring[entry].status;
1041 if (status < 0) {
1042 break;
1043 } else if (status & TD_ES) {
1044 lp->stats.tx_errors++;
1045 if (status & TD_NC) lp->stats.tx_carrier_errors++;
1046 if (status & TD_LC) lp->stats.tx_window_errors++;
1047 if (status & TD_UF) lp->stats.tx_fifo_errors++;
1048 if (status & TD_LC) lp->stats.collisions++;
1049 if (status & TD_EC) lp->pktStats.excessive_collisions++;
1050 if (status & TD_DE) lp->stats.tx_aborted_errors++;
1051
1052 if (status & (TD_LO | TD_NC | TD_EC | TD_LF)) {
1053 lp->lostMedia++;
1054 } else {
1055 outl(POLL_DEMAND, DE4X5_TPD);
1056 }
1057 } else {
1058 lp->stats.tx_packets++;
1059 lp->lostMedia = 0;
1060 }
1061
1062 if (lp->skb[entry] != NULL) {
1063 dev_kfree_skb(lp->skb[entry], FREE_WRITE);
1064 }
1065
1066
1067 lp->tx_old = (++lp->tx_old) % lp->txRingSize;
1068 }
1069
1070 return 0;
1071 }
1072
1073 static int
1074 de4x5_close(struct device *dev)
1075 {
1076 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1077 int iobase = dev->base_addr;
1078 u_long imr, omr;
1079
1080 dev->start = 0;
1081 dev->tbusy = 1;
1082
1083 if (de4x5_debug > 1) {
1084 printk("%s: Shutting down ethercard, status was %8.8x.\n",
1085 dev->name, inl(DE4X5_STS));
1086 }
1087
1088
1089
1090
1091 DISABLE_IRQs;
1092
1093 STOP_DE4X5;
1094
1095
1096
1097
1098 free_irq(dev->irq);
1099 irq2dev_map[dev->irq] = 0;
1100
1101 MOD_DEC_USE_COUNT;
1102
1103 return 0;
1104 }
1105
1106 static struct enet_statistics *
1107 de4x5_get_stats(struct device *dev)
1108 {
1109 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1110 int iobase = dev->base_addr;
1111
1112 lp->stats.rx_missed_errors = (int) inl(DE4X5_MFC);
1113
1114 return &lp->stats;
1115 }
1116
1117 static void load_packet(struct device *dev, char *buf, u_long flags, struct sk_buff *skb)
1118 {
1119 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1120
1121 lp->tx_ring[lp->tx_new].buf = buf;
1122 lp->tx_ring[lp->tx_new].des1 &= TD_TER;
1123 lp->tx_ring[lp->tx_new].des1 |= flags;
1124 lp->skb[lp->tx_new] = skb;
1125 lp->tx_ring[lp->tx_new].status = T_OWN;
1126
1127 return;
1128 }
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 static void
1139 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
1140 {
1141 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1142 int iobase = dev->base_addr;
1143 u_long omr;
1144
1145
1146 if (irq2dev_map[dev->irq] != NULL) {
1147 omr = inl(DE4X5_OMR);
1148
1149 if (num_addrs >= 0) {
1150 SetMulticastFilter(dev, num_addrs, (char *)addrs, lp->setup_frame);
1151
1152
1153 load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET |
1154 SETUP_FRAME_LEN, NULL);
1155 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
1156 outl(POLL_DEMAND, DE4X5_TPD);
1157
1158 omr &= ~OMR_PR;
1159 omr |= OMR_PM;
1160 outl(omr, DE4X5_OMR);
1161 } else {
1162 omr |= OMR_PR;
1163 omr &= ~OMR_PM;
1164 outl(omr, DE4X5_OMR);
1165 }
1166 }
1167 }
1168
1169
1170
1171
1172
1173
1174 static void SetMulticastFilter(struct device *dev, int num_addrs, char *addrs, char *multicast_table)
1175 {
1176 char j, bit, byte;
1177 long *p = (long *) multicast_table;
1178 int i;
1179 u_short hashcode;
1180 u_long crc, poly = CRC_POLYNOMIAL_LE;
1181
1182 if (num_addrs == HASH_TABLE_LEN) {
1183 for (i=0; i<(HASH_TABLE_LEN >> 4); i++) {
1184 *p++ = 0x0000ffff;
1185 }
1186 } else {
1187
1188 memset(multicast_table, 0, (HASH_TABLE_LEN >> 2));
1189 *(multicast_table + (HASH_TABLE_LEN >> 3) - 3) = 0x80;
1190
1191
1192 for (i=0;i<num_addrs;i++) {
1193 if ((*addrs & 0x01) == 1) {
1194 crc = 0xffffffff;
1195 for (byte=0;byte<ETH_ALEN;byte++) {
1196
1197 for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1198 crc = (crc >> 1) ^ (((crc ^ bit) & 0x01) ? poly : 0);
1199 }
1200 }
1201 hashcode = crc & ((1 << 9) - 1);
1202
1203 byte = hashcode >> 3;
1204 bit = 1 << (hashcode & 0x07);
1205
1206 byte <<= 1;
1207 if (byte & 0x02) {
1208 byte -= 1;
1209 }
1210 multicast_table[byte] |= bit;
1211
1212 } else {
1213 addrs += ETH_ALEN;
1214 }
1215 }
1216 }
1217
1218 return;
1219 }
1220
1221
1222
1223
1224
1225 static void eisa_probe(struct device *dev, short ioaddr)
1226 {
1227 int i, maxSlots;
1228 int status;
1229 u_short iobase;
1230 struct bus_type *lp = &bus;
1231
1232 if (!ioaddr && autoprobed) return ;
1233 if ((ioaddr < 0x1000) && (ioaddr > 0)) return;
1234
1235 lp->bus = EISA;
1236
1237 if (ioaddr == 0) {
1238 iobase = EISA_SLOT_INC;
1239 i = 1;
1240 maxSlots = MAX_EISA_SLOTS;
1241 } else {
1242 iobase = ioaddr;
1243 i = (ioaddr >> 12);
1244 maxSlots = i + 1;
1245 }
1246
1247 for (status = -ENODEV; i<maxSlots && dev!=NULL; i++, iobase+=EISA_SLOT_INC) {
1248 if ((DevicePresent(EISA_APROM) == 0) || is_zynx) {
1249 if (check_region(iobase, DE4X5_EISA_TOTAL_SIZE) == 0) {
1250 if ((dev = alloc_device(dev, iobase)) != NULL) {
1251 if ((status = de4x5_hw_init(dev, iobase)) == 0) {
1252 num_de4x5s++;
1253 }
1254 num_eth++;
1255 }
1256 } else if (autoprobed) {
1257 printk("%s: region already allocated at 0x%04x.\n", dev->name, iobase);
1258 }
1259 }
1260 }
1261
1262 return;
1263 }
1264
1265
1266
1267
1268 #define PCI_DEVICE (dev_num << 3)
1269 #define PCI_LAST_DEV 32
1270
1271 static void pci_probe(struct device *dev, short ioaddr)
1272
1273 {
1274 u_char irq;
1275 u_short pb, dev_num, dev_last;
1276 u_short vendor, device, status;
1277 u_long class, iobase;
1278 struct bus_type *lp = &bus;
1279
1280 if (!ioaddr && autoprobed) return ;
1281
1282 if (pcibios_present()) {
1283 lp->bus = PCI;
1284
1285 if (ioaddr < 0x1000) {
1286 pb = (u_short)(ioaddr >> 8);
1287 dev_num = (u_short)(ioaddr & 0xff);
1288 } else {
1289 pb = 0;
1290 dev_num = 0;
1291 }
1292 if (ioaddr > 0) {
1293 dev_last = (dev_num < PCI_LAST_DEV) ? dev_num + 1 : PCI_LAST_DEV;
1294 } else {
1295 dev_last = PCI_LAST_DEV;
1296 }
1297
1298 for (; dev_num < dev_last && dev != NULL; dev_num++) {
1299 pcibios_read_config_dword(pb, PCI_DEVICE, PCI_CLASS_REVISION, &class);
1300 if (class != 0xffffffff) {
1301 pcibios_read_config_word(pb, PCI_DEVICE, PCI_VENDOR_ID, &vendor);
1302 pcibios_read_config_word(pb, PCI_DEVICE, PCI_DEVICE_ID, &device);
1303 if ((vendor == DC21040_VID) && (device == DC21040_DID)) {
1304
1305 lp->device = dev_num;
1306
1307
1308 pcibios_read_config_dword(pb, PCI_DEVICE, PCI_BASE_ADDRESS_0, &iobase);
1309 iobase &= CBIO_MASK;
1310
1311
1312 pcibios_read_config_byte(pb, PCI_DEVICE, PCI_INTERRUPT_LINE, &irq);
1313
1314
1315 pcibios_read_config_word(pb, PCI_DEVICE, PCI_COMMAND, &status);
1316 status |= PCI_COMMAND_IO | PCI_COMMAND_MASTER;
1317 pcibios_write_config_word(pb, PCI_DEVICE, PCI_COMMAND, status);
1318
1319
1320 if ((DevicePresent(DE4X5_APROM) == 0) || is_zynx) {
1321 if (check_region(iobase, DE4X5_PCI_TOTAL_SIZE) == 0) {
1322 if ((dev = alloc_device(dev, iobase)) != NULL) {
1323 dev->irq = irq;
1324 if ((status = de4x5_hw_init(dev, iobase)) == 0) {
1325 num_de4x5s++;
1326 }
1327 num_eth++;
1328 }
1329 } else if (autoprobed) {
1330 printk("%s: region already allocated at 0x%04x.\n", dev->name, (u_short)iobase);
1331 }
1332 }
1333 }
1334 }
1335 }
1336 }
1337
1338 return;
1339 }
1340
1341
1342
1343
1344
1345 static struct device *alloc_device(struct device *dev, int iobase)
1346 {
1347 int addAutoProbe = 0;
1348 struct device *tmp = NULL, *ret;
1349 int (*init)(struct device *) = NULL;
1350
1351
1352
1353
1354 if (!loading_module) {
1355 while (dev->next != NULL) {
1356 if ((dev->base_addr == 0xffe0) || (dev->base_addr == 0)) break;
1357 dev = dev->next;
1358 num_eth++;
1359 }
1360
1361
1362
1363
1364
1365 if ((dev->base_addr == 0) && (num_de4x5s > 0)) {
1366 addAutoProbe++;
1367 tmp = dev->next;
1368 init = dev->init;
1369 }
1370
1371
1372
1373
1374
1375 if ((dev->next == NULL) &&
1376 !((dev->base_addr == 0xffe0) || (dev->base_addr == 0))){
1377 dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1378 GFP_KERNEL);
1379
1380 dev = dev->next;
1381 if (dev == NULL) {
1382 printk("eth%d: Device not initialised, insufficient memory\n",
1383 num_eth);
1384 } else {
1385
1386
1387
1388
1389
1390 dev->name = (char *)(dev + sizeof(struct device));
1391 if (num_eth > 9999) {
1392 sprintf(dev->name,"eth????");
1393 } else {
1394 sprintf(dev->name,"eth%d", num_eth);
1395 }
1396 dev->base_addr = iobase;
1397 dev->next = NULL;
1398 dev->init = &de4x5_probe;
1399 num_de4x5s++;
1400 }
1401 }
1402 ret = dev;
1403
1404
1405
1406
1407
1408 if (ret != NULL) {
1409 if (addAutoProbe) {
1410 for (; (tmp->next!=NULL) && (tmp->base_addr!=0xffe0); tmp=tmp->next);
1411
1412
1413
1414
1415
1416 if ((tmp->next == NULL) && !(tmp->base_addr == 0xffe0)) {
1417 tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1418 GFP_KERNEL);
1419 tmp = tmp->next;
1420 if (tmp == NULL) {
1421 printk("%s: Insufficient memory to extend the device list.\n",
1422 dev->name);
1423 } else {
1424
1425
1426
1427
1428
1429 tmp->name = (char *)(tmp + sizeof(struct device));
1430 if (num_eth > 9999) {
1431 sprintf(tmp->name,"eth????");
1432 } else {
1433 sprintf(tmp->name,"eth%d", num_eth);
1434 }
1435 tmp->base_addr = 0;
1436 tmp->next = NULL;
1437 tmp->init = init;
1438 }
1439 } else {
1440 tmp->base_addr = 0;
1441 }
1442 }
1443 }
1444 } else {
1445 ret = dev;
1446 }
1447
1448 return ret;
1449 }
1450
1451
1452
1453
1454
1455
1456
1457 static int autoconf_media(struct device *dev)
1458 {
1459 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1460 int media, entry, iobase = dev->base_addr;
1461 char frame[64];
1462 u_long i, omr, sisr, linkBad;
1463
1464 u_long t_3s = 8000000;
1465
1466
1467 media = TP;
1468 RESET_SIA;
1469 outl(SICR_OE57 | SICR_SEL | SICR_SRL, DE4X5_SICR);
1470
1471
1472 for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
1473 if (((sisr = inl(DE4X5_SISR)) & SISR_LKF) == 0) linkBad = 0;
1474 if (sisr & SISR_NCR) break;
1475 }
1476
1477 if (linkBad) {
1478
1479 media = BNC;
1480 RESET_SIA;
1481 outl(SIGR_JCK | SIGR_HUJ, DE4X5_SIGR);
1482 outl(STRR_CLD | STRR_CSQ | STRR_RSQ | STRR_DREN | STRR_ECEN, DE4X5_STRR);
1483 outl(SICR_OE57| SICR_OE24 | SICR_OE13 | SICR_SEL |
1484 SICR_AUI | SICR_SRL, DE4X5_SICR);
1485
1486
1487 dce_ms_delay(330);
1488
1489
1490
1491
1492
1493 create_packet(dev, frame, sizeof(frame));
1494
1495
1496 entry = lp->tx_new;
1497 load_packet(dev, frame, TD_LS | TD_FS | TD_AC | sizeof(frame), NULL);
1498
1499
1500 omr = inl(DE4X5_OMR);
1501 outl(omr|OMR_ST, DE4X5_OMR);
1502
1503
1504 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
1505 lp->tx_old = lp->tx_new;
1506
1507
1508
1509
1510
1511 for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
1512 if ((inl(DE4X5_SISR) & SISR_NCR) == 1) break;
1513 if (lp->tx_ring[entry].status >= 0) linkBad=0;
1514 }
1515
1516 outl(omr, DE4X5_OMR);
1517
1518 if (linkBad || (lp->tx_ring[entry].status & TD_ES)) {
1519
1520 media = AUI;
1521 RESET_SIA;
1522 outl(SIGR_JCK | SIGR_HUJ, DE4X5_SIGR);
1523 outl(STRR_CLD | STRR_CSQ | STRR_RSQ | STRR_DREN | STRR_ECEN, DE4X5_STRR);
1524 outl(SICR_OE57| SICR_SEL | SICR_AUI | SICR_SRL, DE4X5_SICR);
1525
1526
1527 dce_ms_delay(330);
1528
1529
1530 entry = lp->tx_new;
1531 load_packet(dev, frame, TD_LS | TD_FS | TD_AC | sizeof(frame), NULL);
1532
1533
1534 omr = inl(DE4X5_OMR);
1535 outl(omr|OMR_ST, DE4X5_OMR);
1536
1537
1538 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
1539 lp->tx_old = lp->tx_new;
1540
1541
1542
1543
1544
1545 for (linkBad=1,i=0;i<t_3s && linkBad;i++) {
1546 if ((inl(DE4X5_SISR) & SISR_NCR) == 1) break;
1547 if (lp->tx_ring[entry].status >= 0) linkBad=0;
1548 }
1549
1550 outl(omr, DE4X5_OMR);
1551
1552 if (linkBad || (lp->tx_ring[entry].status & TD_ES)) {
1553
1554 outl(SICR_RESET, DE4X5_SICR);
1555 outl(STRR_RESET, DE4X5_STRR);
1556 outl(SIGR_RESET, DE4X5_SIGR);
1557
1558 media = NC;
1559 }
1560 }
1561 }
1562
1563 if (de4x5_debug >= 1 ) {
1564 printk("%s: Media is %s.\n",dev->name,
1565 (media == NC ? "unconnected to this device" :
1566 (media == TP ? "TP" :
1567 (media == BNC ? "BNC" :
1568 "AUI"))));
1569 }
1570
1571 if (media) lp->lostMedia = 0;
1572
1573 return media;
1574 }
1575
1576
1577
1578
1579 static void create_packet(struct device *dev, char *frame, int len)
1580 {
1581 int i, j;
1582 char *buf = frame;
1583
1584 for (i=0; i<ETH_ALEN; i++) {
1585 *buf++ = dev->dev_addr[i];
1586 }
1587 for (i=0; i<ETH_ALEN; i++) {
1588 *buf++ = dev->dev_addr[i];
1589 }
1590 for (j=1; j>=0; j--) {
1591 *buf++ = (char) ((len >> 8*j) & 0xff);
1592 }
1593 *buf++ = 0;
1594
1595 for (i=len-4; i<len; i++) {
1596 buf[i] = 0;
1597 }
1598
1599 return;
1600 }
1601
1602
1603
1604
1605 static u_short dce_get_ticks(void)
1606 {
1607 u_short ticks = 0;
1608
1609
1610 outb(TIMER_PORT, TIMER_LATCH);
1611
1612
1613 ticks = inb(TIMER_READ);
1614 ticks |= (inb(TIMER_READ) << 8);
1615
1616 return ticks;
1617 }
1618
1619
1620
1621
1622 static void dce_us_delay(u_long usec)
1623 {
1624 u_long i, start, now, quant=(DELAY_QUANT*1000)/TIMER_TICK+1;
1625
1626 for (i=0; i<usec/DELAY_QUANT; i++) {
1627 start=dce_get_ticks();
1628 for (now=start; (start-now)<quant;) {
1629 now=dce_get_ticks();
1630 if (now > start) {
1631 quant -= start;
1632 start = (1 << TIMER_WIDTH);
1633 }
1634 }
1635 }
1636
1637 return;
1638 }
1639
1640
1641
1642
1643 static void dce_ms_delay(u_long msec)
1644 {
1645 u_long i;
1646
1647 for (i=0; i<msec; i++) {
1648 dce_us_delay(1000);
1649 }
1650
1651 return;
1652 }
1653
1654
1655
1656
1657
1658 static void EISA_signature(char *name, short iobase)
1659 {
1660 unsigned long i;
1661 char *signatures[] = DE4X5_SIGNATURE;
1662 char ManCode[8];
1663 union {
1664 u_long ID;
1665 u_char Id[4];
1666 } Eisa;
1667
1668 strcpy(name, "");
1669 Eisa.ID = inl(iobase);
1670
1671 ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1672 ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1673 ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1674 ManCode[3]=((Eisa.Id[2]&0x0f)+0x30);
1675 ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1676 ManCode[5]='\0';
1677
1678 for (i=0;*signatures[i] != '\0' && *name == '\0';i++) {
1679 if (strstr(ManCode, signatures[i]) != NULL) {
1680 strcpy(name,ManCode);
1681 }
1682 }
1683
1684 return;
1685 }
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699 static int DevicePresent(short aprom_addr)
1700 {
1701 union {
1702 struct {
1703 u_long a;
1704 u_long b;
1705 } llsig;
1706 char Sig[sizeof(long) << 1];
1707 } dev;
1708 char data;
1709 long i, j, tmp;
1710 short sigLength;
1711 int status = 0;
1712 struct bus_type *lp = &bus;
1713
1714 dev.llsig.a = ETH_PROM_SIG;
1715 dev.llsig.b = ETH_PROM_SIG;
1716 sigLength = sizeof(long) << 1;
1717
1718 for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1719 if (lp->bus == PCI) {
1720 while ((tmp = inl(aprom_addr)) < 0);
1721 data = (char)tmp;
1722 } else {
1723 data = inb(aprom_addr);
1724 }
1725 if (dev.Sig[j] == data) {
1726 j++;
1727 } else {
1728 if (data == dev.Sig[0]) {
1729 j=1;
1730 } else {
1731 j=0;
1732 }
1733 }
1734 }
1735
1736 if (j!=sigLength) {
1737 status = -ENODEV;
1738 }
1739
1740 return status;
1741 }
1742
1743 static int aprom_crc(struct device *dev)
1744 {
1745 int iobase = dev->base_addr;
1746 long i, k, tmp;
1747 unsigned short j,chksum;
1748 unsigned char status = 0;
1749 struct bus_type *lp = &bus;
1750
1751 for (i=0,k=0,j=0;j<3;j++) {
1752 k <<= 1 ;
1753 if (k > 0xffff) k-=0xffff;
1754
1755 if (lp->bus == PCI) {
1756 while ((tmp = inl(DE4X5_APROM)) < 0);
1757 k += (u_char) tmp;
1758 dev->dev_addr[i++] = (u_char) tmp;
1759 while ((tmp = inl(DE4X5_APROM)) < 0);
1760 k += (u_short) (tmp << 8);
1761 dev->dev_addr[i++] = (u_char) tmp;
1762 } else {
1763 k += (u_char) (tmp = inb(EISA_APROM));
1764 dev->dev_addr[i++] = (u_char) tmp;
1765 k += (u_short) ((tmp = inb(EISA_APROM)) << 8);
1766 dev->dev_addr[i++] = (u_char) tmp;
1767 }
1768
1769 if (k > 0xffff) k-=0xffff;
1770 }
1771 if (k == 0xffff) k=0;
1772
1773 if (lp->bus == PCI) {
1774 while ((tmp = inl(DE4X5_APROM)) < 0);
1775 chksum = (u_char) tmp;
1776 while ((tmp = inl(DE4X5_APROM)) < 0);
1777 chksum |= (u_short) (tmp << 8);
1778 } else {
1779 chksum = (u_char) inb(EISA_APROM);
1780 chksum |= (u_short) (inb(EISA_APROM) << 8);
1781 }
1782
1783 if (k != chksum) status = -1;
1784
1785 return status;
1786 }
1787
1788
1789
1790
1791
1792 static int de4x5_ioctl(struct device *dev, struct ifreq *rq, int cmd)
1793 {
1794 struct de4x5_private *lp = (struct de4x5_private *)dev->priv;
1795 struct de4x5_ioctl *ioc = (struct de4x5_ioctl *) &rq->ifr_data;
1796 int i, j, iobase = dev->base_addr, status = 0;
1797 u_long omr;
1798 union {
1799 unsigned char addr[(HASH_TABLE_LEN * ETH_ALEN)];
1800 unsigned short sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1801 unsigned long lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1802 } tmp;
1803
1804 switch(ioc->cmd) {
1805 case DE4X5_GET_HWADDR:
1806 for (i=0; i<ETH_ALEN; i++) {
1807 tmp.addr[i] = dev->dev_addr[i];
1808 }
1809 ioc->len = ETH_ALEN;
1810 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1811
1812 break;
1813 case DE4X5_SET_HWADDR:
1814 if (suser()) {
1815 int offset;
1816 char *pa;
1817 u_long omr;
1818
1819 memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1820 for (i=0; i<ETH_ALEN; i++) {
1821 dev->dev_addr[i] = tmp.addr[i];
1822 }
1823 omr = inl(DE4X5_OMR);
1824 if (omr & OMR_HP) {
1825 offset = IMPERF_PA_OFFSET;
1826 } else {
1827 offset = PERF_PA_OFFSET;
1828 }
1829
1830 for (pa=lp->setup_frame+offset, i=0; i<ETH_ALEN; i++) {
1831 *(pa + i) = dev->dev_addr[i];
1832 if (i & 0x01) pa += 2;
1833 }
1834
1835 while (set_bit(0, (void *)&dev->tbusy) != 0);
1836 load_packet(dev, lp->setup_frame, TD_IC | HASH_F | TD_SET |
1837 SETUP_FRAME_LEN, NULL);
1838 lp->tx_new = (++lp->tx_new) % lp->txRingSize;
1839 outl(POLL_DEMAND, DE4X5_TPD);
1840 dev->tbusy = 0;
1841
1842 } else {
1843 status = -EPERM;
1844 }
1845
1846 break;
1847 case DE4X5_SET_PROM:
1848 if (suser()) {
1849 omr = inl(DE4X5_OMR);
1850 omr |= OMR_PR;
1851 omr &= ~OMR_PM;
1852 outl(omr, DE4X5_OMR);
1853 } else {
1854 status = -EPERM;
1855 }
1856
1857 break;
1858 case DE4X5_CLR_PROM:
1859 if (suser()) {
1860 omr = inl(DE4X5_OMR);
1861 omr &= ~OMR_PR;
1862 outb(omr, DE4X5_OMR);
1863 } else {
1864 status = -EPERM;
1865 }
1866
1867 break;
1868 case DE4X5_SAY_BOO:
1869 printk("%s: Boo!\n", dev->name);
1870
1871 break;
1872 case DE4X5_GET_MCA:
1873 ioc->len = (HASH_TABLE_LEN >> 3);
1874 memcpy_tofs(ioc->data, lp->setup_frame, 192);
1875
1876 break;
1877 case DE4X5_SET_MCA:
1878 if (suser()) {
1879 if (ioc->len != HASH_TABLE_LEN) {
1880 memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1881 }
1882 set_multicast_list(dev, ioc->len, tmp.addr);
1883 } else {
1884 status = -EPERM;
1885 }
1886
1887 break;
1888 case DE4X5_CLR_MCA:
1889 if (suser()) {
1890 set_multicast_list(dev, 0, NULL);
1891 } else {
1892 status = -EPERM;
1893 }
1894
1895 break;
1896 case DE4X5_MCA_EN:
1897 if (suser()) {
1898 omr = inl(DE4X5_OMR);
1899 omr |= OMR_PM;
1900 omr &= ~OMR_PR;
1901 outl(omr, DE4X5_OMR);
1902 } else {
1903 status = -EPERM;
1904 }
1905
1906 break;
1907 case DE4X5_GET_STATS:
1908 cli();
1909 memcpy_tofs(ioc->data, &lp->pktStats, sizeof(lp->pktStats));
1910 ioc->len = DE4X5_PKT_STAT_SZ;
1911 sti();
1912
1913 break;
1914 case DE4X5_CLR_STATS:
1915 if (suser()) {
1916 cli();
1917 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1918 sti();
1919 } else {
1920 status = -EPERM;
1921 }
1922
1923 break;
1924 case DE4X5_GET_OMR:
1925 tmp.addr[0] = inl(DE4X5_OMR);
1926 memcpy_tofs(ioc->data, tmp.addr, 1);
1927
1928 break;
1929 case DE4X5_SET_OMR:
1930 if (suser()) {
1931 memcpy_fromfs(tmp.addr, ioc->data, 1);
1932 outl(tmp.addr[0], DE4X5_OMR);
1933 } else {
1934 status = -EPERM;
1935 }
1936
1937 break;
1938 case DE4X5_GET_REG:
1939 tmp.lval[0] = inl(DE4X5_STS);
1940 tmp.lval[1] = inl(DE4X5_BMR);
1941 tmp.lval[2] = inl(DE4X5_IMR);
1942 tmp.lval[3] = inl(DE4X5_OMR);
1943 tmp.lval[4] = inl(DE4X5_SISR);
1944 tmp.lval[5] = inl(DE4X5_SICR);
1945 tmp.lval[6] = inl(DE4X5_STRR);
1946 tmp.lval[7] = inl(DE4X5_SIGR);
1947 memcpy_tofs(ioc->data, tmp.addr, 32);
1948
1949 break;
1950
1951 #define DE4X5_DUMP 0x0f
1952
1953 case DE4X5_DUMP:
1954 j = 0;
1955 tmp.addr[j++] = dev->irq;
1956 for (i=0; i<ETH_ALEN; i++) {
1957 tmp.addr[j++] = dev->dev_addr[i];
1958 }
1959 tmp.addr[j++] = lp->rxRingSize;
1960 tmp.lval[j>>2] = (long)lp->rx_ring; j+=4;
1961 tmp.lval[j>>2] = (long)lp->tx_ring; j+=4;
1962
1963 for (i=0;i<lp->rxRingSize-1;i++){
1964 if (i < 3) {
1965 tmp.lval[j>>2] = (long)&lp->rx_ring[i].status; j+=4;
1966 }
1967 }
1968 tmp.lval[j>>2] = (long)&lp->rx_ring[i].status; j+=4;
1969 for (i=0;i<lp->txRingSize-1;i++){
1970 if (i < 3) {
1971 tmp.lval[j>>2] = (long)&lp->tx_ring[i].status; j+=4;
1972 }
1973 }
1974 tmp.lval[j>>2] = (long)&lp->tx_ring[i].status; j+=4;
1975
1976 for (i=0;i<lp->rxRingSize-1;i++){
1977 if (i < 3) {
1978 tmp.lval[j>>2] = (long)lp->rx_ring[i].buf; j+=4;
1979 }
1980 }
1981 tmp.lval[j>>2] = (long)lp->rx_ring[i].buf; j+=4;
1982 for (i=0;i<lp->txRingSize-1;i++){
1983 if (i < 3) {
1984 tmp.lval[j>>2] = (long)lp->tx_ring[i].buf; j+=4;
1985 }
1986 }
1987 tmp.lval[j>>2] = (long)lp->tx_ring[i].buf; j+=4;
1988
1989 for (i=0;i<lp->rxRingSize;i++){
1990 tmp.lval[j>>2] = lp->rx_ring[i].status; j+=4;
1991 }
1992 for (i=0;i<lp->txRingSize;i++){
1993 tmp.lval[j>>2] = lp->tx_ring[i].status; j+=4;
1994 }
1995
1996 tmp.lval[j>>2] = inl(DE4X5_STS); j+=4;
1997 tmp.lval[j>>2] = inl(DE4X5_BMR); j+=4;
1998 tmp.lval[j>>2] = inl(DE4X5_IMR); j+=4;
1999 tmp.lval[j>>2] = inl(DE4X5_OMR); j+=4;
2000 tmp.lval[j>>2] = inl(DE4X5_SISR); j+=4;
2001 tmp.lval[j>>2] = inl(DE4X5_SICR); j+=4;
2002 tmp.lval[j>>2] = inl(DE4X5_STRR); j+=4;
2003 tmp.lval[j>>2] = inl(DE4X5_SIGR); j+=4;
2004
2005 tmp.addr[j++] = lp->txRingSize;
2006 tmp.addr[j++] = dev->tbusy;
2007
2008 ioc->len = j;
2009 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
2010
2011 break;
2012 default:
2013 status = -EOPNOTSUPP;
2014 }
2015
2016 return status;
2017 }
2018
2019 #ifdef MODULE
2020 char kernel_version[] = UTS_RELEASE;
2021 static struct device thisDE4X5 = {
2022 " ",
2023 0, 0, 0, 0,
2024 0x2000, 10,
2025 0, 0, 0, NULL, de4x5_probe };
2026
2027 int io=0x000b;
2028 int irq=10;
2029
2030 int
2031 init_module(void)
2032 {
2033 thisDE4X5.base_addr=io;
2034 thisDE4X5.irq=irq;
2035 if (register_netdev(&thisDE4X5) != 0)
2036 return -EIO;
2037 return 0;
2038 }
2039
2040 void
2041 cleanup_module(void)
2042 {
2043 struct de4x5_private *lp = (struct de4x5_private *) thisDE4X5.priv;
2044
2045 if (MOD_IN_USE) {
2046 printk("%s: device busy, remove delayed\n",thisDE4X5.name);
2047 } else {
2048 release_region(thisDE4X5.base_addr, (lp->bus == PCI ?
2049 DE4X5_PCI_TOTAL_SIZE :
2050 DE4X5_EISA_TOTAL_SIZE));
2051 if (lp) {
2052 kfree_s(lp->rx_ring[0].buf, RX_BUFF_SZ * NUM_RX_DESC + LWPAD);
2053 }
2054 kfree_s(thisDE4X5.priv, sizeof(struct de4x5_private) + LWPAD);
2055 thisDE4X5.priv = NULL;
2056
2057 unregister_netdev(&thisDE4X5);
2058 }
2059 }
2060 #endif
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071