This source file includes following definitions.
- depca_probe
- depca_hw_init
- depca_open
- depca_init_ring
- depca_start_xmit
- depca_interrupt
- depca_rx
- depca_tx
- depca_close
- LoadCSRs
- InitRestartDepca
- depca_get_stats
- set_multicast_list
- SetMulticastFilter
- isa_probe
- eisa_probe
- alloc_device
- DepcaSignature
- DevicePresent
- get_hw_addr
- load_packet
- EISA_signature
- depca_dbg_open
- depca_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 static const char *version = "depca.c:v0.42 95/12/27 davies@wanton.lkg.dec.com\n";
208
209 #include <linux/module.h>
210
211 #include <linux/kernel.h>
212 #include <linux/sched.h>
213 #include <linux/string.h>
214 #include <linux/ptrace.h>
215 #include <linux/errno.h>
216 #include <linux/ioport.h>
217 #include <linux/malloc.h>
218 #include <linux/interrupt.h>
219 #include <linux/delay.h>
220 #include <asm/segment.h>
221 #include <asm/bitops.h>
222 #include <asm/io.h>
223 #include <asm/dma.h>
224
225 #include <linux/netdevice.h>
226 #include <linux/etherdevice.h>
227 #include <linux/skbuff.h>
228
229 #include <linux/time.h>
230 #include <linux/types.h>
231 #include <linux/unistd.h>
232
233 #include "depca.h"
234
235 #ifdef DEPCA_DEBUG
236 static int depca_debug = DEPCA_DEBUG;
237 #else
238 static int depca_debug = 1;
239 #endif
240
241 #define DEPCA_NDA 0xffe0
242
243
244
245
246 #define PROBE_LENGTH 32
247 #define ETH_PROM_SIG 0xAA5500FFUL
248
249
250
251
252
253
254
255
256 #define NUM_RX_DESC 8
257 #define NUM_TX_DESC 8
258 #define RX_BUFF_SZ 1536
259 #define TX_BUFF_SZ 1536
260
261 #define CRC_POLYNOMIAL_BE 0x04c11db7UL
262 #define CRC_POLYNOMIAL_LE 0xedb88320UL
263
264
265
266
267 #define DEPCA_EISA_IO_PORTS 0x0c00
268 #define MAX_EISA_SLOTS 16
269 #define EISA_SLOT_INC 0x1000
270
271
272
273
274 #define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
275 #define DEPCA_IO_PORTS {0x300, 0x200, 0}
276 #define DEPCA_TOTAL_SIZE 0x10
277 static short mem_chkd = 0;
278
279
280
281
282 #define DEPCA_SIGNATURE {"DEPCA",\
283 "DE100","DE101",\
284 "DE200","DE201","DE202",\
285 "DE210",\
286 "DE422",\
287 ""}
288 static enum {DEPCA, de100, de101, de200, de201, de202, de210, de422, unknown} adapter;
289
290
291
292
293 #define DEPCA_STRLEN 16
294 #define MAX_NUM_DEPCAS 2
295
296
297
298
299
300
301
302 #define ALIGN4 ((u_long)4 - 1)
303 #define ALIGN8 ((u_long)8 - 1)
304 #define ALIGN ALIGN8
305
306
307
308
309 struct depca_rx_desc {
310 volatile s32 base;
311 s16 buf_length;
312 s16 msg_length;
313 };
314
315 struct depca_tx_desc {
316 volatile s32 base;
317 s16 length;
318 s16 misc;
319 };
320
321 #define LA_MASK 0x0000ffff
322
323
324
325
326
327 struct depca_init {
328 u16 mode;
329 u8 phys_addr[ETH_ALEN];
330 u8 mcast_table[8];
331 u32 rx_ring;
332 u32 tx_ring;
333 };
334
335 #define DEPCA_PKT_STAT_SZ 16
336 #define DEPCA_PKT_BIN_SZ 128
337
338 struct depca_private {
339 char devname[DEPCA_STRLEN];
340 char adapter_name[DEPCA_STRLEN];
341 char adapter;
342 struct depca_rx_desc *rx_ring;
343 struct depca_tx_desc *tx_ring;
344 struct depca_init init_block;
345 char *rx_memcpy[NUM_RX_DESC];
346 char *tx_memcpy[NUM_TX_DESC];
347 u_long bus_offset;
348 u_long sh_mem;
349 u_long dma_buffs;
350 int rx_new, tx_new;
351 int rx_old, tx_old;
352 struct enet_statistics stats;
353 struct {
354 u32 bins[DEPCA_PKT_STAT_SZ];
355 u32 unicast;
356 u32 multicast;
357 u32 broadcast;
358 u32 excessive_collisions;
359 u32 tx_underruns;
360 u32 excessive_underruns;
361 } pktStats;
362 int txRingMask;
363 int rxRingMask;
364 s32 rx_rlen;
365 s32 tx_rlen;
366 };
367
368
369
370
371
372
373
374
375 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
376 lp->tx_old+lp->txRingMask-lp->tx_new:\
377 lp->tx_old -lp->tx_new-1)
378
379
380
381
382 static int depca_open(struct device *dev);
383 static int depca_start_xmit(struct sk_buff *skb, struct device *dev);
384 static void depca_interrupt(int irq, void *dev_id, struct pt_regs * regs);
385 static int depca_close(struct device *dev);
386 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd);
387 static struct enet_statistics *depca_get_stats(struct device *dev);
388 static void set_multicast_list(struct device *dev);
389
390
391
392
393 static int depca_hw_init(struct device *dev, u_long ioaddr);
394 static void depca_init_ring(struct device *dev);
395 static int depca_rx(struct device *dev);
396 static int depca_tx(struct device *dev);
397
398 static void LoadCSRs(struct device *dev);
399 static int InitRestartDepca(struct device *dev);
400 static void DepcaSignature(char *name, u_long paddr);
401 static int DevicePresent(u_long ioaddr);
402 static int get_hw_addr(struct device *dev);
403 static int EISA_signature(char *name, s32 eisa_id);
404 static void SetMulticastFilter(struct device *dev);
405 static void isa_probe(struct device *dev, u_long iobase);
406 static void eisa_probe(struct device *dev, u_long iobase);
407 static struct device *alloc_device(struct device *dev, u_long iobase);
408 static int load_packet(struct device *dev, struct sk_buff *skb);
409 static void depca_dbg_open(struct device *dev);
410
411 #ifdef MODULE
412 int init_module(void);
413 void cleanup_module(void);
414 static int autoprobed = 1, loading_module = 1;
415 # else
416 static u_char de1xx_irq[] = {2,3,4,5,7,9,0};
417 static u_char de2xx_irq[] = {5,9,10,11,15,0};
418 static u_char de422_irq[] = {5,9,10,11,0};
419 static u_char *depca_irq;
420 static int autoprobed = 0, loading_module = 0;
421 #endif
422
423 static char name[DEPCA_STRLEN];
424 static int num_depcas = 0, num_eth = 0;
425 static int mem=0;
426
427 static char *adapter_name = '\0';
428
429
430
431
432
433 #define STOP_DEPCA \
434 outw(CSR0, DEPCA_ADDR);\
435 outw(STOP, DEPCA_DATA)
436
437
438
439 int depca_probe(struct device *dev)
440 {
441 int tmp = num_depcas, status = -ENODEV;
442 u_long iobase = dev->base_addr;
443
444 if ((iobase == 0) && loading_module){
445 printk("Autoprobing is not supported when loading a module based driver.\n");
446 status = -EIO;
447 } else {
448 isa_probe(dev, iobase);
449 eisa_probe(dev, iobase);
450
451 if ((tmp == num_depcas) && (iobase != 0) && loading_module) {
452 printk("%s: depca_probe() cannot find device at 0x%04lx.\n", dev->name,
453 iobase);
454 }
455
456
457
458
459
460 for (; (dev->priv == NULL) && (dev->next != NULL); dev = dev->next);
461
462 if (dev->priv) status = 0;
463 if (iobase == 0) autoprobed = 1;
464 }
465
466 return status;
467 }
468
469 static int
470 depca_hw_init(struct device *dev, u_long ioaddr)
471 {
472 struct depca_private *lp;
473 int i, j, offset, netRAM, mem_len, status=0;
474 s16 nicsr;
475 u_long mem_start=0, mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
476
477 STOP_DEPCA;
478
479 nicsr = inb(DEPCA_NICSR);
480 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
481 outb(nicsr, DEPCA_NICSR);
482
483 if (inw(DEPCA_DATA) == STOP) {
484 if (mem == 0) {
485 for (; mem_base[mem_chkd]; mem_chkd++) {
486 mem_start = mem_base[mem_chkd];
487 DepcaSignature(name, mem_start);
488 if (*name != '\0') break;
489 }
490 } else {
491 mem_start = mem;
492 if (adapter_name) {
493 strcpy(name, adapter_name);
494 } else{
495 DepcaSignature(name, mem_start);
496 }
497 }
498
499 if ((*name != '\0') && mem_start) {
500 dev->base_addr = ioaddr;
501
502 if ((ioaddr&0x0fff)==DEPCA_EISA_IO_PORTS) {
503 printk("%s: %s at 0x%04lx (EISA slot %d)",
504 dev->name, name, ioaddr, (int)((ioaddr>>12)&0x0f));
505 } else {
506 printk("%s: %s at 0x%04lx", dev->name, name, ioaddr);
507 }
508
509 printk(", h/w address ");
510 status = get_hw_addr(dev);
511 for (i=0; i<ETH_ALEN - 1; i++) {
512 printk("%2.2x:", dev->dev_addr[i]);
513 }
514 printk("%2.2x", dev->dev_addr[i]);
515
516 if (status == 0) {
517
518 netRAM = ((adapter != DEPCA) ? 64 : 48);
519 if ((nicsr & _128KB) && (adapter == de422)) netRAM = 128;
520 offset = 0x0000;
521
522
523 if (nicsr & BUF) {
524 offset = 0x8000;
525 nicsr &= ~BS;
526 netRAM -= 32;
527 }
528 mem_start += offset;
529 if ((mem_len = (NUM_RX_DESC*(sizeof(struct depca_rx_desc)+RX_BUFF_SZ) +
530 NUM_TX_DESC*(sizeof(struct depca_tx_desc)+TX_BUFF_SZ) +
531 sizeof(struct depca_init))) <=
532 (netRAM<<10)) {
533 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
534
535
536 if (adapter != DEPCA) {
537 nicsr |= SHE;
538 outb(nicsr, DEPCA_NICSR);
539 }
540
541
542 dev->priv = (void *) kmalloc(sizeof(struct depca_private), GFP_KERNEL);
543 if (dev->priv == NULL)
544 return -ENOMEM;
545 lp = (struct depca_private *)dev->priv;
546 memset((char *)dev->priv, 0, sizeof(struct depca_private));
547 lp->adapter = adapter;
548 sprintf(lp->adapter_name,"%s (%s)", name, dev->name);
549 request_region(ioaddr, DEPCA_TOTAL_SIZE, lp->adapter_name);
550
551
552 lp->sh_mem = mem_start;
553 mem_start += sizeof(struct depca_init);
554
555
556 mem_start = (mem_start + ALIGN) & ~ALIGN;
557 lp->rx_ring = (struct depca_rx_desc *)mem_start;
558
559 mem_start += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
560 lp->tx_ring = (struct depca_tx_desc *)mem_start;
561
562 mem_start += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
563 lp->bus_offset = mem_start & 0x00ff0000;
564 mem_start &= LA_MASK;
565
566 lp->dma_buffs = mem_start;
567
568
569 lp->rxRingMask = NUM_RX_DESC - 1;
570 lp->txRingMask = NUM_TX_DESC - 1;
571
572
573 for (i=0, j = lp->rxRingMask; j>0; i++) {
574 j >>= 1;
575 }
576 lp->rx_rlen = (s32)(i << 29);
577 for (i=0, j = lp->txRingMask; j>0; i++) {
578 j >>= 1;
579 }
580 lp->tx_rlen = (s32)(i << 29);
581
582
583 depca_init_ring(dev);
584
585
586 LoadCSRs(dev);
587
588
589 nicsr = ((nicsr & ~IM)|IEN);
590 outb(nicsr, DEPCA_NICSR);
591
592
593
594 if (dev->irq < 2) {
595 #ifndef MODULE
596 unsigned char irqnum;
597 autoirq_setup(0);
598
599
600 switch (lp->adapter) {
601 case DEPCA:
602 case de100:
603 case de101:
604 depca_irq = de1xx_irq;
605 break;
606 case de200:
607 case de201:
608 case de202:
609 case de210:
610 depca_irq = de2xx_irq;
611 break;
612 case de422:
613 depca_irq = de422_irq;
614 break;
615 }
616
617
618 outw(INEA | INIT, DEPCA_DATA);
619
620 irqnum = autoirq_report(1);
621 if (!irqnum) {
622 printk(" and failed to detect IRQ line.\n");
623 status = -ENXIO;
624 } else {
625 for (dev->irq=0,i=0; (depca_irq[i]) && (!dev->irq); i++) {
626 if (irqnum == depca_irq[i]) {
627 dev->irq = irqnum;
628 printk(" and uses IRQ%d.\n", dev->irq);
629 }
630 }
631
632 if (!dev->irq) {
633 printk(" but incorrect IRQ line detected.\n");
634 status = -ENXIO;
635 }
636 }
637 #endif
638 } else {
639 printk(" and assigned IRQ%d.\n", dev->irq);
640 }
641 if (status) release_region(ioaddr, DEPCA_TOTAL_SIZE);
642 } else {
643 printk(",\n requests %dkB RAM: only %dkB is available!\n",
644 (mem_len>>10), netRAM);
645 status = -ENXIO;
646 }
647 } else {
648 printk(" which has an Ethernet PROM CRC error.\n");
649 status = -ENXIO;
650 }
651 }
652 if (!status) {
653 if (depca_debug > 0) {
654 printk(version);
655 }
656
657
658 dev->open = &depca_open;
659 dev->hard_start_xmit = &depca_start_xmit;
660 dev->stop = &depca_close;
661 dev->get_stats = &depca_get_stats;
662 dev->set_multicast_list = &set_multicast_list;
663 dev->do_ioctl = &depca_ioctl;
664
665 dev->mem_start = 0;
666
667
668 ether_setup(dev);
669 } else {
670 if (dev->priv) {
671 kfree_s(dev->priv, sizeof(struct depca_private));
672 dev->priv = NULL;
673 }
674 }
675 } else {
676 status = -ENXIO;
677 }
678
679 return status;
680 }
681
682
683 static int
684 depca_open(struct device *dev)
685 {
686 struct depca_private *lp = (struct depca_private *)dev->priv;
687 u_long ioaddr = dev->base_addr;
688 s16 nicsr;
689 int status = 0;
690
691 irq2dev_map[dev->irq] = dev;
692 STOP_DEPCA;
693 nicsr = inb(DEPCA_NICSR);
694
695
696 if (adapter != DEPCA) {
697 nicsr |= SHE;
698 outb(nicsr, DEPCA_NICSR);
699 }
700
701
702 depca_init_ring(dev);
703 LoadCSRs(dev);
704
705 depca_dbg_open(dev);
706
707 if (request_irq(dev->irq, &depca_interrupt, 0, lp->adapter_name, NULL)) {
708 printk("depca_open(): Requested IRQ%d is busy\n",dev->irq);
709 status = -EAGAIN;
710 } else {
711
712
713 nicsr = ((nicsr & ~IM & ~LED)|IEN);
714 outb(nicsr, DEPCA_NICSR);
715 outw(CSR0,DEPCA_ADDR);
716
717 dev->tbusy = 0;
718 dev->interrupt = 0;
719 dev->start = 1;
720
721 status = InitRestartDepca(dev);
722
723 if (depca_debug > 1){
724 printk("CSR0: 0x%4.4x\n",inw(DEPCA_DATA));
725 printk("nicsr: 0x%02x\n",inb(DEPCA_NICSR));
726 }
727 }
728
729 MOD_INC_USE_COUNT;
730
731 return status;
732 }
733
734
735 static void
736 depca_init_ring(struct device *dev)
737 {
738 struct depca_private *lp = (struct depca_private *)dev->priv;
739 u_int i;
740 u_long p;
741
742
743 set_bit(0, (void *)&dev->tbusy);
744
745 lp->rx_new = lp->tx_new = 0;
746 lp->rx_old = lp->tx_old = 0;
747
748
749 for (i = 0; i <= lp->rxRingMask; i++) {
750 writel((p=lp->dma_buffs+i*RX_BUFF_SZ) | R_OWN, &lp->rx_ring[i].base);
751 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
752 lp->rx_memcpy[i]=(char *)(p+lp->bus_offset);
753 }
754 for (i = 0; i <= lp->txRingMask; i++) {
755 writel((p=lp->dma_buffs+(i+lp->txRingMask+1)*TX_BUFF_SZ) & 0x00ffffff,
756 &lp->tx_ring[i].base);
757 lp->tx_memcpy[i]=(char *)(p+lp->bus_offset);
758 }
759
760
761 lp->init_block.rx_ring = ((u32)((u_long)lp->rx_ring)&LA_MASK) | lp->rx_rlen;
762 lp->init_block.tx_ring = ((u32)((u_long)lp->tx_ring)&LA_MASK) | lp->tx_rlen;
763
764 SetMulticastFilter(dev);
765
766 for (i = 0; i < ETH_ALEN; i++) {
767 lp->init_block.phys_addr[i] = dev->dev_addr[i];
768 }
769
770 lp->init_block.mode = 0x0000;
771
772 return;
773 }
774
775
776
777
778 static int
779 depca_start_xmit(struct sk_buff *skb, struct device *dev)
780 {
781 struct depca_private *lp = (struct depca_private *)dev->priv;
782 u_long ioaddr = dev->base_addr;
783 int status = 0;
784
785
786 if (dev->tbusy) {
787 int tickssofar = jiffies - dev->trans_start;
788 if (tickssofar < 1*HZ) {
789 status = -1;
790 } else {
791 printk("%s: transmit timed out, status %04x, resetting.\n",
792 dev->name, inw(DEPCA_DATA));
793
794 STOP_DEPCA;
795 depca_init_ring(dev);
796 LoadCSRs(dev);
797 dev->interrupt = UNMASK_INTERRUPTS;
798 dev->start = 1;
799 dev->tbusy=0;
800 dev->trans_start = jiffies;
801 InitRestartDepca(dev);
802 }
803 return status;
804 } else if (skb == NULL) {
805 dev_tint(dev);
806 } else if (skb->len > 0) {
807
808 if (set_bit(0, (void*)&dev->tbusy) != 0) {
809 printk("%s: Transmitter access conflict.\n", dev->name);
810 status = -1;
811 } else {
812 if (TX_BUFFS_AVAIL) {
813 status = load_packet(dev, skb);
814
815 if (!status) {
816
817 outw(CSR0, DEPCA_ADDR);
818 outw(INEA | TDMD, DEPCA_DATA);
819
820 dev->trans_start = jiffies;
821 dev_kfree_skb(skb, FREE_WRITE);
822 }
823 if (TX_BUFFS_AVAIL) {
824 dev->tbusy=0;
825 }
826 } else {
827 status = -1;
828 }
829 }
830 }
831
832 return status;
833 }
834
835
836
837
838 static void
839 depca_interrupt(int irq, void *dev_id, struct pt_regs * regs)
840 {
841 struct device *dev = (struct device *)(irq2dev_map[irq]);
842 struct depca_private *lp;
843 s16 csr0, nicsr;
844 u_long ioaddr;
845
846 if (dev == NULL) {
847 printk ("depca_interrupt(): irq %d for unknown device.\n", irq);
848 } else {
849 lp = (struct depca_private *)dev->priv;
850 ioaddr = dev->base_addr;
851
852 if (dev->interrupt)
853 printk("%s: Re-entering the interrupt handler.\n", dev->name);
854
855 dev->interrupt = MASK_INTERRUPTS;
856
857
858 nicsr = inb(DEPCA_NICSR);
859 nicsr |= (IM|LED);
860 outb(nicsr, DEPCA_NICSR);
861
862 outw(CSR0, DEPCA_ADDR);
863 csr0 = inw(DEPCA_DATA);
864
865
866 outw(csr0 & INTE, DEPCA_DATA);
867
868 if (csr0 & RINT)
869 depca_rx(dev);
870
871 if (csr0 & TINT)
872 depca_tx(dev);
873
874 if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy) {
875 dev->tbusy = 0;
876 mark_bh(NET_BH);
877 }
878
879
880 nicsr = (nicsr & ~IM & ~LED);
881 outb(nicsr, DEPCA_NICSR);
882
883 dev->interrupt = UNMASK_INTERRUPTS;
884 }
885
886 return;
887 }
888
889 static int
890 depca_rx(struct device *dev)
891 {
892 struct depca_private *lp = (struct depca_private *)dev->priv;
893 int i, entry;
894 s32 status;
895
896 for (entry=lp->rx_new;
897 !(readl(&lp->rx_ring[entry].base) & R_OWN);
898 entry=lp->rx_new){
899 status = readl(&lp->rx_ring[entry].base) >> 16 ;
900 if (status & R_STP) {
901 lp->rx_old = entry;
902 }
903 if (status & R_ENP) {
904 if (status & R_ERR) {
905 lp->stats.rx_errors++;
906 if (status & R_FRAM) lp->stats.rx_frame_errors++;
907 if (status & R_OFLO) lp->stats.rx_over_errors++;
908 if (status & R_CRC) lp->stats.rx_crc_errors++;
909 if (status & R_BUFF) lp->stats.rx_fifo_errors++;
910 } else {
911 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length);
912 struct sk_buff *skb;
913
914 skb = dev_alloc_skb(pkt_len+2);
915 if (skb != NULL) {
916 unsigned char *buf;
917 skb_reserve(skb,2);
918 buf = skb_put(skb,pkt_len);
919 skb->dev = dev;
920 if (entry < lp->rx_old) {
921 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
922 memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], len);
923 memcpy_fromio(buf + len, lp->rx_memcpy[0], pkt_len-len);
924 } else {
925 memcpy_fromio(buf, lp->rx_memcpy[lp->rx_old], pkt_len);
926 }
927
928
929
930
931
932 skb->protocol=eth_type_trans(skb,dev);
933 netif_rx(skb);
934
935
936
937
938 lp->stats.rx_packets++;
939 for (i=1; i<DEPCA_PKT_STAT_SZ-1; i++) {
940 if (pkt_len < (i*DEPCA_PKT_BIN_SZ)) {
941 lp->pktStats.bins[i]++;
942 i = DEPCA_PKT_STAT_SZ;
943 }
944 }
945 if (buf[0] & 0x01) {
946 if ((*(s16 *)&buf[0] == -1) &&
947 (*(s16 *)&buf[2] == -1) &&
948 (*(s16 *)&buf[4] == -1)) {
949 lp->pktStats.broadcast++;
950 } else {
951 lp->pktStats.multicast++;
952 }
953 } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
954 (*(s16 *)&buf[2] == *(s16 *)&dev->dev_addr[2]) &&
955 (*(s16 *)&buf[4] == *(s16 *)&dev->dev_addr[4])) {
956 lp->pktStats.unicast++;
957 }
958
959 lp->pktStats.bins[0]++;
960 if (lp->pktStats.bins[0] == 0) {
961 memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
962 }
963 } else {
964 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
965 lp->stats.rx_dropped++;
966 break;
967 }
968 }
969
970 for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
971 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,
972 &lp->rx_ring[lp->rx_old].base);
973 }
974 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
975 }
976
977
978
979
980 lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
981 }
982
983 return 0;
984 }
985
986
987
988
989 static int
990 depca_tx(struct device *dev)
991 {
992 struct depca_private *lp = (struct depca_private *)dev->priv;
993 int entry;
994 s32 status;
995 u_long ioaddr = dev->base_addr;
996
997 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
998 status = readl(&lp->tx_ring[entry].base) >> 16 ;
999
1000 if (status < 0) {
1001 break;
1002 } else if (status & T_ERR) {
1003 status = readl(&lp->tx_ring[entry].misc);
1004 lp->stats.tx_errors++;
1005 if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
1006 if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
1007 if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
1008 if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
1009 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1010
1011 outw(CSR0, DEPCA_ADDR);
1012 outw(INEA | TDMD, DEPCA_DATA);
1013 }
1014 } else if (status & (T_MORE | T_ONE)) {
1015 lp->stats.collisions++;
1016 } else {
1017 lp->stats.tx_packets++;
1018 }
1019
1020
1021 lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1022 }
1023
1024 return 0;
1025 }
1026
1027 static int
1028 depca_close(struct device *dev)
1029 {
1030 struct depca_private *lp = (struct depca_private *)dev->priv;
1031 s16 nicsr;
1032 u_long ioaddr = dev->base_addr;
1033
1034 dev->start = 0;
1035 dev->tbusy = 1;
1036
1037 outw(CSR0, DEPCA_ADDR);
1038
1039 if (depca_debug > 1) {
1040 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1041 dev->name, inw(DEPCA_DATA));
1042 }
1043
1044
1045
1046
1047
1048 outw(STOP, DEPCA_DATA);
1049
1050
1051
1052
1053 if (lp->adapter != DEPCA) {
1054 nicsr = inb(DEPCA_NICSR);
1055 nicsr &= ~SHE;
1056 outb(nicsr, DEPCA_NICSR);
1057 }
1058
1059
1060
1061
1062 free_irq(dev->irq, NULL);
1063 irq2dev_map[dev->irq] = NULL;
1064
1065 MOD_DEC_USE_COUNT;
1066
1067 return 0;
1068 }
1069
1070 static void LoadCSRs(struct device *dev)
1071 {
1072 struct depca_private *lp = (struct depca_private *)dev->priv;
1073 u_long ioaddr = dev->base_addr;
1074
1075 outw(CSR1, DEPCA_ADDR);
1076 outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
1077 outw(CSR2, DEPCA_ADDR);
1078 outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
1079 outw(CSR3, DEPCA_ADDR);
1080 outw(ACON, DEPCA_DATA);
1081
1082 outw(CSR0, DEPCA_ADDR);
1083
1084 return;
1085 }
1086
1087 static int InitRestartDepca(struct device *dev)
1088 {
1089 struct depca_private *lp = (struct depca_private *)dev->priv;
1090 u_long ioaddr = dev->base_addr;
1091 int i, status=0;
1092
1093
1094 memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1095
1096 outw(CSR0, DEPCA_ADDR);
1097 outw(INIT, DEPCA_DATA);
1098
1099
1100 for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
1101
1102 if (i!=100) {
1103
1104 outw(IDON | INEA | STRT, DEPCA_DATA);
1105 if (depca_debug > 2) {
1106 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1107 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1108 }
1109 } else {
1110 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1111 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1112 status = -1;
1113 }
1114
1115 return status;
1116 }
1117
1118 static struct enet_statistics *
1119 depca_get_stats(struct device *dev)
1120 {
1121 struct depca_private *lp = (struct depca_private *)dev->priv;
1122
1123
1124
1125 return &lp->stats;
1126 }
1127
1128
1129
1130
1131 static void
1132 set_multicast_list(struct device *dev)
1133 {
1134 struct depca_private *lp = (struct depca_private *)dev->priv;
1135 u_long ioaddr = dev->base_addr;
1136
1137 if (irq2dev_map[dev->irq] != NULL) {
1138 while(dev->tbusy);
1139 set_bit(0, (void*)&dev->tbusy);
1140 while(lp->tx_old != lp->tx_new);
1141
1142 STOP_DEPCA;
1143 depca_init_ring(dev);
1144
1145 if (dev->flags & IFF_PROMISC) {
1146 lp->init_block.mode |= PROM;
1147 } else {
1148 SetMulticastFilter(dev);
1149 lp->init_block.mode &= ~PROM;
1150 }
1151
1152 LoadCSRs(dev);
1153 InitRestartDepca(dev);
1154 dev->tbusy = 0;
1155 }
1156 }
1157
1158
1159
1160
1161
1162
1163
1164 static void SetMulticastFilter(struct device *dev)
1165 {
1166 struct depca_private *lp = (struct depca_private *)dev->priv;
1167 struct dev_mc_list *dmi=dev->mc_list;
1168 char *addrs;
1169 int i, j, bit, byte;
1170 u16 hashcode;
1171 s32 crc, poly = CRC_POLYNOMIAL_BE;
1172
1173 if (dev->flags & IFF_ALLMULTI) {
1174 for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
1175 lp->init_block.mcast_table[i] = (char)0xff;
1176 }
1177 } else {
1178 for (i=0; i<(HASH_TABLE_LEN>>3); i++){
1179 lp->init_block.mcast_table[i]=0;
1180 }
1181
1182 for (i=0;i<dev->mc_count;i++) {
1183 addrs=dmi->dmi_addr;
1184 dmi=dmi->next;
1185 if ((*addrs & 0x01) == 1) {
1186 crc = 0xffffffff;
1187 for (byte=0;byte<ETH_ALEN;byte++) {
1188
1189 for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1190 crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
1191 }
1192 }
1193 hashcode = (crc & 1);
1194 for (j=0;j<5;j++) {
1195 hashcode = (hashcode << 1) | ((crc>>=1) & 1);
1196 }
1197
1198
1199 byte = hashcode >> 3;
1200 bit = 1 << (hashcode & 0x07);
1201 lp->init_block.mcast_table[byte] |= bit;
1202 }
1203 }
1204 }
1205
1206 return;
1207 }
1208
1209
1210
1211
1212 static void isa_probe(struct device *dev, u_long ioaddr)
1213 {
1214 int i = num_depcas, maxSlots;
1215 s32 ports[] = DEPCA_IO_PORTS;
1216
1217 if (!ioaddr && autoprobed) return ;
1218 if (ioaddr > 0x400) return;
1219 if (i >= MAX_NUM_DEPCAS) return;
1220
1221 if (ioaddr == 0) {
1222 maxSlots = MAX_NUM_DEPCAS;
1223 } else {
1224 ports[i] = ioaddr;
1225 maxSlots = i + 1;
1226 }
1227
1228 for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
1229 if (DevicePresent(ports[i]) == 0) {
1230 if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1231 if ((dev = alloc_device(dev, ports[i])) != NULL) {
1232 if (depca_hw_init(dev, ports[i]) == 0) {
1233 num_depcas++;
1234 }
1235 num_eth++;
1236 }
1237 } else if (autoprobed) {
1238 printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]);
1239 }
1240 }
1241 }
1242
1243 return;
1244 }
1245
1246
1247
1248
1249
1250 static void eisa_probe(struct device *dev, u_long ioaddr)
1251 {
1252 int i, maxSlots;
1253 u_long iobase;
1254 char name[DEPCA_STRLEN];
1255
1256 if (!ioaddr && autoprobed) return ;
1257 if ((ioaddr < 0x400) && (ioaddr > 0)) return;
1258
1259 if (ioaddr == 0) {
1260 iobase = EISA_SLOT_INC;
1261 i = 1;
1262 maxSlots = MAX_EISA_SLOTS;
1263 } else {
1264 iobase = ioaddr;
1265 i = (ioaddr >> 12);
1266 maxSlots = i + 1;
1267 }
1268 if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
1269
1270 for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1271 if (EISA_signature(name, EISA_ID)) {
1272 if (DevicePresent(iobase) == 0) {
1273 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1274 if ((dev = alloc_device(dev, iobase)) != NULL) {
1275 if (depca_hw_init(dev, iobase) == 0) {
1276 num_depcas++;
1277 }
1278 num_eth++;
1279 }
1280 } else if (autoprobed) {
1281 printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase);
1282 }
1283 }
1284 }
1285 }
1286
1287 return;
1288 }
1289
1290
1291
1292
1293
1294 static struct device *alloc_device(struct device *dev, u_long iobase)
1295 {
1296 int addAutoProbe = 0;
1297 struct device *tmp = NULL, *ret;
1298 int (*init)(struct device *) = NULL;
1299
1300
1301
1302
1303 if (!loading_module) {
1304 while (dev->next != NULL) {
1305 if ((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) break;
1306 dev = dev->next;
1307 num_eth++;
1308 }
1309
1310
1311
1312
1313
1314 if ((dev->base_addr == 0) && (num_depcas > 0)) {
1315 addAutoProbe++;
1316 tmp = dev->next;
1317 init = dev->init;
1318 }
1319
1320
1321
1322
1323
1324 if ((dev->next == NULL) &&
1325 !((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0))){
1326 dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1327 GFP_KERNEL);
1328
1329 dev = dev->next;
1330 if (dev == NULL) {
1331 printk("eth%d: Device not initialised, insufficient memory\n",
1332 num_eth);
1333 } else {
1334
1335
1336
1337
1338
1339 dev->name = (char *)(dev + sizeof(struct device));
1340 if (num_eth > 9999) {
1341 sprintf(dev->name,"eth????");
1342 } else {
1343 sprintf(dev->name,"eth%d", num_eth);
1344 }
1345 dev->base_addr = iobase;
1346 dev->next = NULL;
1347 dev->init = &depca_probe;
1348 num_depcas++;
1349 }
1350 }
1351 ret = dev;
1352
1353
1354
1355
1356
1357 if (ret != NULL) {
1358 if (addAutoProbe) {
1359 for (;(tmp->next!=NULL) && (tmp->base_addr!=DEPCA_NDA); tmp=tmp->next);
1360
1361
1362
1363
1364
1365 if ((tmp->next == NULL) && !(tmp->base_addr == DEPCA_NDA)) {
1366 tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1367 GFP_KERNEL);
1368 tmp = tmp->next;
1369 if (tmp == NULL) {
1370 printk("%s: Insufficient memory to extend the device list.\n",
1371 dev->name);
1372 } else {
1373
1374
1375
1376
1377
1378 tmp->name = (char *)(tmp + sizeof(struct device));
1379 if (num_eth > 9999) {
1380 sprintf(tmp->name,"eth????");
1381 } else {
1382 sprintf(tmp->name,"eth%d", num_eth);
1383 }
1384 tmp->base_addr = 0;
1385 tmp->next = NULL;
1386 tmp->init = init;
1387 }
1388 } else {
1389 tmp->base_addr = 0;
1390 }
1391 }
1392 }
1393 } else {
1394 ret = dev;
1395 }
1396
1397 return ret;
1398 }
1399
1400
1401
1402
1403
1404
1405 static void DepcaSignature(char *name, u_long paddr)
1406 {
1407 u_int i,j,k;
1408 const char *signatures[] = DEPCA_SIGNATURE;
1409 char tmpstr[16];
1410
1411 for (i=0;i<16;i++) {
1412 tmpstr[i] = readb(paddr+0xc000+i);
1413 }
1414
1415 strcpy(name,"");
1416 for (i=0;*signatures[i]!='\0' && *name=='\0';i++) {
1417 for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
1418 if (signatures[i][k] == tmpstr[j]) {
1419 k++;
1420 } else {
1421 k=0;
1422 }
1423 }
1424 if (k == strlen(signatures[i])) {
1425 strcpy(name,signatures[i]);
1426 }
1427 }
1428
1429 adapter = i - 1;
1430
1431 return;
1432 }
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449 static int DevicePresent(u_long ioaddr)
1450 {
1451 union {
1452 struct {
1453 u32 a;
1454 u32 b;
1455 } llsig;
1456 char Sig[sizeof(u32) << 1];
1457 } dev;
1458 short sigLength=0;
1459 s8 data;
1460 s16 nicsr;
1461 int i, j, status = 0;
1462
1463 data = inb(DEPCA_PROM);
1464 data = inb(DEPCA_PROM);
1465
1466 if (data == 0x08) {
1467 nicsr = inb(DEPCA_NICSR);
1468 nicsr |= AAC;
1469 outb(nicsr, DEPCA_NICSR);
1470 }
1471
1472 dev.llsig.a = ETH_PROM_SIG;
1473 dev.llsig.b = ETH_PROM_SIG;
1474 sigLength = sizeof(u32) << 1;
1475
1476 for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1477 data = inb(DEPCA_PROM);
1478 if (dev.Sig[j] == data) {
1479 j++;
1480 } else {
1481 if (data == dev.Sig[0]) {
1482 j=1;
1483 } else {
1484 j=0;
1485 }
1486 }
1487 }
1488
1489 if (j!=sigLength) {
1490 status = -ENODEV;
1491 }
1492
1493 return status;
1494 }
1495
1496
1497
1498
1499
1500
1501 static int get_hw_addr(struct device *dev)
1502 {
1503 u_long ioaddr = dev->base_addr;
1504 int i, k, tmp, status = 0;
1505 u_short j, x, chksum;
1506
1507 x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1508
1509 for (i=0,k=0,j=0;j<3;j++) {
1510 k <<= 1 ;
1511 if (k > 0xffff) k-=0xffff;
1512
1513 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1514 dev->dev_addr[i++] = (u_char) tmp;
1515 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1516 dev->dev_addr[i++] = (u_char) tmp;
1517
1518 if (k > 0xffff) k-=0xffff;
1519 }
1520 if (k == 0xffff) k=0;
1521
1522 chksum = (u_char) inb(DEPCA_PROM + x);
1523 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1524 if (k != chksum) status = -1;
1525
1526 return status;
1527 }
1528
1529
1530
1531
1532 static int load_packet(struct device *dev, struct sk_buff *skb)
1533 {
1534 struct depca_private *lp = (struct depca_private *)dev->priv;
1535 int i, entry, end, len, status = 0;
1536
1537 entry = lp->tx_new;
1538 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1539 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {
1540
1541
1542
1543
1544 if (end < entry) {
1545 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1546 memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
1547 memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
1548 } else {
1549 memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
1550 }
1551
1552
1553 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1554 for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1555
1556 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1557 writew(0x0000, &lp->tx_ring[i].misc);
1558 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);
1559 len -= TX_BUFF_SZ;
1560 }
1561
1562 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1563 writew(0x0000, &lp->tx_ring[end].misc);
1564 writew(-len, &lp->tx_ring[end].length);
1565
1566
1567 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1568
1569 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1570
1571 for (i=end; i!=entry; --i) {
1572
1573 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1574 if (i == 0) i=lp->txRingMask+1;
1575 }
1576 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1577
1578 lp->tx_new = (++end) & lp->txRingMask;
1579 } else {
1580 status = -1;
1581 }
1582
1583 return status;
1584 }
1585
1586
1587
1588
1589 static int EISA_signature(char *name, s32 eisa_id)
1590 {
1591 u_int i;
1592 const char *signatures[] = DEPCA_SIGNATURE;
1593 char ManCode[DEPCA_STRLEN];
1594 union {
1595 s32 ID;
1596 char Id[4];
1597 } Eisa;
1598 int status = 0;
1599
1600 *name = '\0';
1601 Eisa.ID = inl(eisa_id);
1602
1603 ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1604 ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1605 ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1606 ManCode[3]=(( Eisa.Id[2]&0x0f)+0x30);
1607 ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1608 ManCode[5]='\0';
1609
1610 for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1611 if (strstr(ManCode, signatures[i]) != NULL) {
1612 strcpy(name,ManCode);
1613 status = 1;
1614 }
1615 }
1616
1617 return status;
1618 }
1619
1620 static void depca_dbg_open(struct device *dev)
1621 {
1622 struct depca_private *lp = (struct depca_private *)dev->priv;
1623 u_long ioaddr = dev->base_addr;
1624 struct depca_init *p = (struct depca_init *)lp->sh_mem;
1625 int i;
1626
1627 if (depca_debug > 1){
1628
1629 memcpy_toio((char *)lp->sh_mem,&lp->init_block,sizeof(struct depca_init));
1630
1631 printk("%s: depca open with irq %d\n",dev->name,dev->irq);
1632 printk("Descriptor head addresses:\n");
1633 printk("\t0x%lx 0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring);
1634 printk("Descriptor addresses:\nRX: ");
1635 for (i=0;i<lp->rxRingMask;i++){
1636 if (i < 3) {
1637 printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
1638 }
1639 }
1640 printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
1641 printk("TX: ");
1642 for (i=0;i<lp->txRingMask;i++){
1643 if (i < 3) {
1644 printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
1645 }
1646 }
1647 printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
1648 printk("\nDescriptor buffers:\nRX: ");
1649 for (i=0;i<lp->rxRingMask;i++){
1650 if (i < 3) {
1651 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1652 }
1653 }
1654 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1655 printk("TX: ");
1656 for (i=0;i<lp->txRingMask;i++){
1657 if (i < 3) {
1658 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1659 }
1660 }
1661 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1662 printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem);
1663 printk("\tmode: 0x%4.4x\n",readw(&p->mode));
1664 printk("\tphysical address: ");
1665 for (i=0;i<ETH_ALEN-1;i++){
1666 printk("%2.2x:",(u_char)readb(&p->phys_addr[i]));
1667 }
1668 printk("%2.2x\n",(u_char)readb(&p->phys_addr[i]));
1669 printk("\tmulticast hash table: ");
1670 for (i=0;i<(HASH_TABLE_LEN >> 3)-1;i++){
1671 printk("%2.2x:",(u_char)readb(&p->mcast_table[i]));
1672 }
1673 printk("%2.2x\n",(u_char)readb(&p->mcast_table[i]));
1674 printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring));
1675 printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring));
1676 printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs);
1677 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n",
1678 (int)lp->rxRingMask + 1,
1679 lp->rx_rlen);
1680 printk("TX: %d Log2(txRingMask): 0x%8.8x\n",
1681 (int)lp->txRingMask + 1,
1682 lp->tx_rlen);
1683 outw(CSR2,DEPCA_ADDR);
1684 printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
1685 outw(CSR1,DEPCA_ADDR);
1686 printk("%4.4x\n",inw(DEPCA_DATA));
1687 outw(CSR3,DEPCA_ADDR);
1688 printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
1689 }
1690
1691 return;
1692 }
1693
1694
1695
1696
1697
1698
1699 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
1700 {
1701 struct depca_private *lp = (struct depca_private *)dev->priv;
1702 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1703 int i, status = 0;
1704 u_long ioaddr = dev->base_addr;
1705 union {
1706 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1707 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1708 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1709 } tmp;
1710
1711 switch(ioc->cmd) {
1712 case DEPCA_GET_HWADDR:
1713 for (i=0; i<ETH_ALEN; i++) {
1714 tmp.addr[i] = dev->dev_addr[i];
1715 }
1716 ioc->len = ETH_ALEN;
1717 if (!(status = verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len))) {
1718 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1719 }
1720
1721 break;
1722 case DEPCA_SET_HWADDR:
1723 if (suser()) {
1724 if (!(status = verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN))) {
1725 memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1726 for (i=0; i<ETH_ALEN; i++) {
1727 dev->dev_addr[i] = tmp.addr[i];
1728 }
1729 while(dev->tbusy);
1730 set_bit(0, (void*)&dev->tbusy);
1731 while(lp->tx_old != lp->tx_new);
1732
1733 STOP_DEPCA;
1734 depca_init_ring(dev);
1735 LoadCSRs(dev);
1736 InitRestartDepca(dev);
1737 dev->tbusy = 0;
1738 }
1739 } else {
1740 status = -EPERM;
1741 }
1742
1743 break;
1744 case DEPCA_SET_PROM:
1745 if (suser()) {
1746 while(dev->tbusy);
1747 set_bit(0, (void*)&dev->tbusy);
1748 while(lp->tx_old != lp->tx_new);
1749
1750 STOP_DEPCA;
1751 depca_init_ring(dev);
1752 lp->init_block.mode |= PROM;
1753
1754 LoadCSRs(dev);
1755 InitRestartDepca(dev);
1756 dev->tbusy = 0;
1757 } else {
1758 status = -EPERM;
1759 }
1760
1761 break;
1762 case DEPCA_CLR_PROM:
1763 if (suser()) {
1764 while(dev->tbusy);
1765 set_bit(0, (void*)&dev->tbusy);
1766 while(lp->tx_old != lp->tx_new);
1767
1768 STOP_DEPCA;
1769 depca_init_ring(dev);
1770 lp->init_block.mode &= ~PROM;
1771
1772 LoadCSRs(dev);
1773 InitRestartDepca(dev);
1774 dev->tbusy = 0;
1775 } else {
1776 status = -EPERM;
1777 }
1778
1779 break;
1780 case DEPCA_SAY_BOO:
1781 printk("%s: Boo!\n", dev->name);
1782
1783 break;
1784 case DEPCA_GET_MCA:
1785 ioc->len = (HASH_TABLE_LEN >> 3);
1786 if (!(status = verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1787 memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len);
1788 }
1789
1790 break;
1791 case DEPCA_SET_MCA:
1792 if (suser()) {
1793 if (!(status=verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len))) {
1794 memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1795 set_multicast_list(dev);
1796 }
1797 } else {
1798 status = -EPERM;
1799 }
1800
1801 break;
1802 case DEPCA_CLR_MCA:
1803 if (suser()) {
1804 set_multicast_list(dev);
1805 } else {
1806 status = -EPERM;
1807 }
1808
1809 break;
1810 case DEPCA_MCA_EN:
1811 if (suser()) {
1812 set_multicast_list(dev);
1813 } else {
1814 status = -EPERM;
1815 }
1816
1817 break;
1818 case DEPCA_GET_STATS:
1819 cli();
1820 ioc->len = sizeof(lp->pktStats);
1821 if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1822 memcpy_tofs(ioc->data, &lp->pktStats, ioc->len);
1823 }
1824 sti();
1825
1826 break;
1827 case DEPCA_CLR_STATS:
1828 if (suser()) {
1829 cli();
1830 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1831 sti();
1832 } else {
1833 status = -EPERM;
1834 }
1835
1836 break;
1837 case DEPCA_GET_REG:
1838 i=0;
1839 tmp.sval[i++] = inw(DEPCA_NICSR);
1840 outw(CSR0, DEPCA_ADDR);
1841 tmp.sval[i++] = inw(DEPCA_DATA);
1842 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
1843 ioc->len = i+sizeof(struct depca_init);
1844 if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1845 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1846 }
1847
1848 break;
1849 default:
1850 status = -EOPNOTSUPP;
1851 }
1852
1853 return status;
1854 }
1855
1856 #ifdef MODULE
1857 static char devicename[9] = { 0, };
1858 static struct device thisDepca = {
1859 devicename,
1860 0, 0, 0, 0,
1861 0x200, 7,
1862 0, 0, 0, NULL, depca_probe };
1863
1864 static int irq=7;
1865 static int io=0x200;
1866
1867
1868 int
1869 init_module(void)
1870 {
1871 thisDepca.irq=irq;
1872 thisDepca.base_addr=io;
1873
1874 if (register_netdev(&thisDepca) != 0)
1875 return -EIO;
1876
1877 return 0;
1878 }
1879
1880 void
1881 cleanup_module(void)
1882 {
1883 if (thisDepca.priv) {
1884 kfree(thisDepca.priv);
1885 thisDepca.priv = NULL;
1886 }
1887 thisDepca.irq=0;
1888
1889 unregister_netdev(&thisDepca);
1890 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
1891 }
1892 #endif
1893
1894
1895
1896
1897
1898
1899
1900
1901