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, 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,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)) {
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, 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) && (*(s32 *)&buf[2] == -1)) {
947 lp->pktStats.broadcast++;
948 } else {
949 lp->pktStats.multicast++;
950 }
951 } else if ((*(s16 *)&buf[0] == *(s16 *)&dev->dev_addr[0]) &&
952 (*(s32 *)&buf[2] == *(s32 *)&dev->dev_addr[2])) {
953 lp->pktStats.unicast++;
954 }
955
956 lp->pktStats.bins[0]++;
957 if (lp->pktStats.bins[0] == 0) {
958 memset((char *)&lp->pktStats, 0, sizeof(lp->pktStats));
959 }
960 } else {
961 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
962 lp->stats.rx_dropped++;
963 break;
964 }
965 }
966
967 for (; lp->rx_old!=entry; lp->rx_old=(++lp->rx_old)&lp->rxRingMask) {
968 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN,
969 &lp->rx_ring[lp->rx_old].base);
970 }
971 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
972 }
973
974
975
976
977 lp->rx_new = (++lp->rx_new) & lp->rxRingMask;
978 }
979
980 return 0;
981 }
982
983
984
985
986 static int
987 depca_tx(struct device *dev)
988 {
989 struct depca_private *lp = (struct depca_private *)dev->priv;
990 int entry;
991 s32 status;
992 u_long ioaddr = dev->base_addr;
993
994 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
995 status = readl(&lp->tx_ring[entry].base) >> 16 ;
996
997 if (status < 0) {
998 break;
999 } else if (status & T_ERR) {
1000 status = readl(&lp->tx_ring[entry].misc);
1001 lp->stats.tx_errors++;
1002 if (status & TMD3_RTRY) lp->stats.tx_aborted_errors++;
1003 if (status & TMD3_LCAR) lp->stats.tx_carrier_errors++;
1004 if (status & TMD3_LCOL) lp->stats.tx_window_errors++;
1005 if (status & TMD3_UFLO) lp->stats.tx_fifo_errors++;
1006 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1007
1008 outw(CSR0, DEPCA_ADDR);
1009 outw(INEA | TDMD, DEPCA_DATA);
1010 }
1011 } else if (status & (T_MORE | T_ONE)) {
1012 lp->stats.collisions++;
1013 } else {
1014 lp->stats.tx_packets++;
1015 }
1016
1017
1018 lp->tx_old = (++lp->tx_old) & lp->txRingMask;
1019 }
1020
1021 return 0;
1022 }
1023
1024 static int
1025 depca_close(struct device *dev)
1026 {
1027 struct depca_private *lp = (struct depca_private *)dev->priv;
1028 s16 nicsr;
1029 u_long ioaddr = dev->base_addr;
1030
1031 dev->start = 0;
1032 dev->tbusy = 1;
1033
1034 outw(CSR0, DEPCA_ADDR);
1035
1036 if (depca_debug > 1) {
1037 printk("%s: Shutting down ethercard, status was %2.2x.\n",
1038 dev->name, inw(DEPCA_DATA));
1039 }
1040
1041
1042
1043
1044
1045 outw(STOP, DEPCA_DATA);
1046
1047
1048
1049
1050 if (lp->adapter != DEPCA) {
1051 nicsr = inb(DEPCA_NICSR);
1052 nicsr &= ~SHE;
1053 outb(nicsr, DEPCA_NICSR);
1054 }
1055
1056
1057
1058
1059 free_irq(dev->irq);
1060 irq2dev_map[dev->irq] = NULL;
1061
1062 MOD_DEC_USE_COUNT;
1063
1064 return 0;
1065 }
1066
1067 static void LoadCSRs(struct device *dev)
1068 {
1069 struct depca_private *lp = (struct depca_private *)dev->priv;
1070 u_long ioaddr = dev->base_addr;
1071
1072 outw(CSR1, DEPCA_ADDR);
1073 outw((u16)(lp->sh_mem & LA_MASK), DEPCA_DATA);
1074 outw(CSR2, DEPCA_ADDR);
1075 outw((u16)((lp->sh_mem & LA_MASK) >> 16), DEPCA_DATA);
1076 outw(CSR3, DEPCA_ADDR);
1077 outw(ACON, DEPCA_DATA);
1078
1079 outw(CSR0, DEPCA_ADDR);
1080
1081 return;
1082 }
1083
1084 static int InitRestartDepca(struct device *dev)
1085 {
1086 struct depca_private *lp = (struct depca_private *)dev->priv;
1087 u_long ioaddr = dev->base_addr;
1088 int i, status=0;
1089
1090
1091 memcpy_toio((char *)lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1092
1093 outw(CSR0, DEPCA_ADDR);
1094 outw(INIT, DEPCA_DATA);
1095
1096
1097 for (i=0;(i<100) && !(inw(DEPCA_DATA) & IDON); i++);
1098
1099 if (i!=100) {
1100
1101 outw(IDON | INEA | STRT, DEPCA_DATA);
1102 if (depca_debug > 2) {
1103 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1104 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1105 }
1106 } else {
1107 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n",
1108 dev->name, i, lp->sh_mem, inw(DEPCA_DATA));
1109 status = -1;
1110 }
1111
1112 return status;
1113 }
1114
1115 static struct enet_statistics *
1116 depca_get_stats(struct device *dev)
1117 {
1118 struct depca_private *lp = (struct depca_private *)dev->priv;
1119
1120
1121
1122 return &lp->stats;
1123 }
1124
1125
1126
1127
1128 static void
1129 set_multicast_list(struct device *dev)
1130 {
1131 struct depca_private *lp = (struct depca_private *)dev->priv;
1132 u_long ioaddr = dev->base_addr;
1133
1134 if (irq2dev_map[dev->irq] != NULL) {
1135 while(dev->tbusy);
1136 set_bit(0, (void*)&dev->tbusy);
1137 while(lp->tx_old != lp->tx_new);
1138
1139 STOP_DEPCA;
1140 depca_init_ring(dev);
1141
1142 if (dev->flags & IFF_PROMISC) {
1143 lp->init_block.mode |= PROM;
1144 } else {
1145 SetMulticastFilter(dev);
1146 lp->init_block.mode &= ~PROM;
1147 }
1148
1149 LoadCSRs(dev);
1150 InitRestartDepca(dev);
1151 dev->tbusy = 0;
1152 }
1153 }
1154
1155
1156
1157
1158
1159
1160
1161 static void SetMulticastFilter(struct device *dev)
1162 {
1163 struct depca_private *lp = (struct depca_private *)dev->priv;
1164 struct dev_mc_list *dmi=dev->mc_list;
1165 char *addrs;
1166 int i, j, bit, byte;
1167 u16 hashcode;
1168 s32 crc, poly = CRC_POLYNOMIAL_BE;
1169
1170 if (dev->flags & IFF_ALLMULTI) {
1171 for (i=0; i<(HASH_TABLE_LEN>>3); i++) {
1172 lp->init_block.mcast_table[i] = (char)0xff;
1173 }
1174 } else {
1175 for (i=0; i<(HASH_TABLE_LEN>>3); i++){
1176 lp->init_block.mcast_table[i]=0;
1177 }
1178
1179 for (i=0;i<dev->mc_count;i++) {
1180 addrs=dmi->dmi_addr;
1181 dmi=dmi->next;
1182 if ((*addrs & 0x01) == 1) {
1183 crc = 0xffffffff;
1184 for (byte=0;byte<ETH_ALEN;byte++) {
1185
1186 for (bit = *addrs++,j=0;j<8;j++, bit>>=1) {
1187 crc = (crc << 1) ^ ((((crc<0?1:0) ^ bit) & 0x01) ? poly : 0);
1188 }
1189 }
1190 hashcode = (crc & 1);
1191 for (j=0;j<5;j++) {
1192 hashcode = (hashcode << 1) | ((crc>>=1) & 1);
1193 }
1194
1195
1196 byte = hashcode >> 3;
1197 bit = 1 << (hashcode & 0x07);
1198 lp->init_block.mcast_table[byte] |= bit;
1199 }
1200 }
1201 }
1202
1203 return;
1204 }
1205
1206
1207
1208
1209 static void isa_probe(struct device *dev, u_long ioaddr)
1210 {
1211 int i = num_depcas, maxSlots;
1212 s32 ports[] = DEPCA_IO_PORTS;
1213
1214 if (!ioaddr && autoprobed) return ;
1215 if (ioaddr > 0x400) return;
1216 if (i >= MAX_NUM_DEPCAS) return;
1217
1218 if (ioaddr == 0) {
1219 maxSlots = MAX_NUM_DEPCAS;
1220 } else {
1221 ports[i] = ioaddr;
1222 maxSlots = i + 1;
1223 }
1224
1225 for (; (i<maxSlots) && (dev!=NULL) && ports[i]; i++) {
1226 if (DevicePresent(ports[i]) == 0) {
1227 if (check_region(ports[i], DEPCA_TOTAL_SIZE) == 0) {
1228 if ((dev = alloc_device(dev, ports[i])) != NULL) {
1229 if (depca_hw_init(dev, ports[i]) == 0) {
1230 num_depcas++;
1231 }
1232 num_eth++;
1233 }
1234 } else if (autoprobed) {
1235 printk("%s: region already allocated at 0x%04x.\n", dev->name,ports[i]);
1236 }
1237 }
1238 }
1239
1240 return;
1241 }
1242
1243
1244
1245
1246
1247 static void eisa_probe(struct device *dev, u_long ioaddr)
1248 {
1249 int i, maxSlots;
1250 u_long iobase;
1251 char name[DEPCA_STRLEN];
1252
1253 if (!ioaddr && autoprobed) return ;
1254 if ((ioaddr < 0x400) && (ioaddr > 0)) return;
1255
1256 if (ioaddr == 0) {
1257 iobase = EISA_SLOT_INC;
1258 i = 1;
1259 maxSlots = MAX_EISA_SLOTS;
1260 } else {
1261 iobase = ioaddr;
1262 i = (ioaddr >> 12);
1263 maxSlots = i + 1;
1264 }
1265 if ((iobase & 0x0fff) == 0) iobase += DEPCA_EISA_IO_PORTS;
1266
1267 for (; (i<maxSlots) && (dev!=NULL); i++, iobase+=EISA_SLOT_INC) {
1268 if (EISA_signature(name, EISA_ID)) {
1269 if (DevicePresent(iobase) == 0) {
1270 if (check_region(iobase, DEPCA_TOTAL_SIZE) == 0) {
1271 if ((dev = alloc_device(dev, iobase)) != NULL) {
1272 if (depca_hw_init(dev, iobase) == 0) {
1273 num_depcas++;
1274 }
1275 num_eth++;
1276 }
1277 } else if (autoprobed) {
1278 printk("%s: region already allocated at 0x%04lx.\n",dev->name,iobase);
1279 }
1280 }
1281 }
1282 }
1283
1284 return;
1285 }
1286
1287
1288
1289
1290
1291 static struct device *alloc_device(struct device *dev, u_long iobase)
1292 {
1293 int addAutoProbe = 0;
1294 struct device *tmp = NULL, *ret;
1295 int (*init)(struct device *) = NULL;
1296
1297
1298
1299
1300 if (!loading_module) {
1301 while (dev->next != NULL) {
1302 if ((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0)) break;
1303 dev = dev->next;
1304 num_eth++;
1305 }
1306
1307
1308
1309
1310
1311 if ((dev->base_addr == 0) && (num_depcas > 0)) {
1312 addAutoProbe++;
1313 tmp = dev->next;
1314 init = dev->init;
1315 }
1316
1317
1318
1319
1320
1321 if ((dev->next == NULL) &&
1322 !((dev->base_addr == DEPCA_NDA) || (dev->base_addr == 0))){
1323 dev->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1324 GFP_KERNEL);
1325
1326 dev = dev->next;
1327 if (dev == NULL) {
1328 printk("eth%d: Device not initialised, insufficient memory\n",
1329 num_eth);
1330 } else {
1331
1332
1333
1334
1335
1336 dev->name = (char *)(dev + sizeof(struct device));
1337 if (num_eth > 9999) {
1338 sprintf(dev->name,"eth????");
1339 } else {
1340 sprintf(dev->name,"eth%d", num_eth);
1341 }
1342 dev->base_addr = iobase;
1343 dev->next = NULL;
1344 dev->init = &depca_probe;
1345 num_depcas++;
1346 }
1347 }
1348 ret = dev;
1349
1350
1351
1352
1353
1354 if (ret != NULL) {
1355 if (addAutoProbe) {
1356 for (;(tmp->next!=NULL) && (tmp->base_addr!=DEPCA_NDA); tmp=tmp->next);
1357
1358
1359
1360
1361
1362 if ((tmp->next == NULL) && !(tmp->base_addr == DEPCA_NDA)) {
1363 tmp->next = (struct device *)kmalloc(sizeof(struct device) + 8,
1364 GFP_KERNEL);
1365 tmp = tmp->next;
1366 if (tmp == NULL) {
1367 printk("%s: Insufficient memory to extend the device list.\n",
1368 dev->name);
1369 } else {
1370
1371
1372
1373
1374
1375 tmp->name = (char *)(tmp + sizeof(struct device));
1376 if (num_eth > 9999) {
1377 sprintf(tmp->name,"eth????");
1378 } else {
1379 sprintf(tmp->name,"eth%d", num_eth);
1380 }
1381 tmp->base_addr = 0;
1382 tmp->next = NULL;
1383 tmp->init = init;
1384 }
1385 } else {
1386 tmp->base_addr = 0;
1387 }
1388 }
1389 }
1390 } else {
1391 ret = dev;
1392 }
1393
1394 return ret;
1395 }
1396
1397
1398
1399
1400
1401
1402 static void DepcaSignature(char *name, u_long paddr)
1403 {
1404 u_int i,j,k;
1405 const char *signatures[] = DEPCA_SIGNATURE;
1406 char tmpstr[16];
1407
1408 for (i=0;i<16;i++) {
1409 tmpstr[i] = readb(paddr+0xc000+i);
1410 }
1411
1412 strcpy(name,"");
1413 for (i=0;*signatures[i]!='\0' && *name=='\0';i++) {
1414 for (j=0,k=0;j<16 && k<strlen(signatures[i]);j++) {
1415 if (signatures[i][k] == tmpstr[j]) {
1416 k++;
1417 } else {
1418 k=0;
1419 }
1420 }
1421 if (k == strlen(signatures[i])) {
1422 strcpy(name,signatures[i]);
1423 }
1424 }
1425
1426 adapter = i - 1;
1427
1428 return;
1429 }
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446 static int DevicePresent(u_long ioaddr)
1447 {
1448 union {
1449 struct {
1450 u32 a;
1451 u32 b;
1452 } llsig;
1453 char Sig[sizeof(u32) << 1];
1454 } dev;
1455 short sigLength=0;
1456 s8 data;
1457 s16 nicsr;
1458 int i, j, status = 0;
1459
1460 data = inb(DEPCA_PROM);
1461 data = inb(DEPCA_PROM);
1462
1463 if (data == 0x08) {
1464 nicsr = inb(DEPCA_NICSR);
1465 nicsr |= AAC;
1466 outb(nicsr, DEPCA_NICSR);
1467 }
1468
1469 dev.llsig.a = ETH_PROM_SIG;
1470 dev.llsig.b = ETH_PROM_SIG;
1471 sigLength = sizeof(u32) << 1;
1472
1473 for (i=0,j=0;j<sigLength && i<PROBE_LENGTH+sigLength-1;i++) {
1474 data = inb(DEPCA_PROM);
1475 if (dev.Sig[j] == data) {
1476 j++;
1477 } else {
1478 if (data == dev.Sig[0]) {
1479 j=1;
1480 } else {
1481 j=0;
1482 }
1483 }
1484 }
1485
1486 if (j!=sigLength) {
1487 status = -ENODEV;
1488 }
1489
1490 return status;
1491 }
1492
1493
1494
1495
1496
1497
1498 static int get_hw_addr(struct device *dev)
1499 {
1500 u_long ioaddr = dev->base_addr;
1501 int i, k, tmp, status = 0;
1502 u_short j, x, chksum;
1503
1504 x = (((adapter == de100) || (adapter == de101)) ? 1 : 0);
1505
1506 for (i=0,k=0,j=0;j<3;j++) {
1507 k <<= 1 ;
1508 if (k > 0xffff) k-=0xffff;
1509
1510 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1511 dev->dev_addr[i++] = (u_char) tmp;
1512 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1513 dev->dev_addr[i++] = (u_char) tmp;
1514
1515 if (k > 0xffff) k-=0xffff;
1516 }
1517 if (k == 0xffff) k=0;
1518
1519 chksum = (u_char) inb(DEPCA_PROM + x);
1520 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1521 if (k != chksum) status = -1;
1522
1523 return status;
1524 }
1525
1526
1527
1528
1529 static int load_packet(struct device *dev, struct sk_buff *skb)
1530 {
1531 struct depca_private *lp = (struct depca_private *)dev->priv;
1532 int i, entry, end, len, status = 0;
1533
1534 entry = lp->tx_new;
1535 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1536 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {
1537
1538
1539
1540
1541 if (end < entry) {
1542 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1543 memcpy_toio(lp->tx_memcpy[entry], skb->data, len);
1544 memcpy_toio(lp->tx_memcpy[0], skb->data + len, skb->len - len);
1545 } else {
1546 memcpy_toio(lp->tx_memcpy[entry], skb->data, skb->len);
1547 }
1548
1549
1550 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1551 for (i = entry; i != end; i = (++i) & lp->txRingMask) {
1552
1553 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1554 writew(0x0000, &lp->tx_ring[i].misc);
1555 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);
1556 len -= TX_BUFF_SZ;
1557 }
1558
1559 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1560 writew(0x0000, &lp->tx_ring[end].misc);
1561 writew(-len, &lp->tx_ring[end].length);
1562
1563
1564 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1565
1566 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1567
1568 for (i=end; i!=entry; --i) {
1569
1570 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1571 if (i == 0) i=lp->txRingMask+1;
1572 }
1573 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1574
1575 lp->tx_new = (++end) & lp->txRingMask;
1576 } else {
1577 status = -1;
1578 }
1579
1580 return status;
1581 }
1582
1583
1584
1585
1586 static int EISA_signature(char *name, s32 eisa_id)
1587 {
1588 u_int i;
1589 const char *signatures[] = DEPCA_SIGNATURE;
1590 char ManCode[DEPCA_STRLEN];
1591 union {
1592 s32 ID;
1593 char Id[4];
1594 } Eisa;
1595 int status = 0;
1596
1597 *name = '\0';
1598 Eisa.ID = inl(eisa_id);
1599
1600 ManCode[0]=(((Eisa.Id[0]>>2)&0x1f)+0x40);
1601 ManCode[1]=(((Eisa.Id[1]&0xe0)>>5)+((Eisa.Id[0]&0x03)<<3)+0x40);
1602 ManCode[2]=(((Eisa.Id[2]>>4)&0x0f)+0x30);
1603 ManCode[3]=(( Eisa.Id[2]&0x0f)+0x30);
1604 ManCode[4]=(((Eisa.Id[3]>>4)&0x0f)+0x30);
1605 ManCode[5]='\0';
1606
1607 for (i=0;(*signatures[i] != '\0') && (*name == '\0');i++) {
1608 if (strstr(ManCode, signatures[i]) != NULL) {
1609 strcpy(name,ManCode);
1610 status = 1;
1611 }
1612 }
1613
1614 return status;
1615 }
1616
1617 static void depca_dbg_open(struct device *dev)
1618 {
1619 struct depca_private *lp = (struct depca_private *)dev->priv;
1620 u_long ioaddr = dev->base_addr;
1621 struct depca_init *p = (struct depca_init *)lp->sh_mem;
1622 int i;
1623
1624 if (depca_debug > 1){
1625
1626 memcpy_toio((char *)lp->sh_mem,&lp->init_block,sizeof(struct depca_init));
1627
1628 printk("%s: depca open with irq %d\n",dev->name,dev->irq);
1629 printk("Descriptor head addresses:\n");
1630 printk("\t0x%lx 0x%lx\n",(u_long)lp->rx_ring, (u_long)lp->tx_ring);
1631 printk("Descriptor addresses:\nRX: ");
1632 for (i=0;i<lp->rxRingMask;i++){
1633 if (i < 3) {
1634 printk("0x%8.8lx ", (long) &lp->rx_ring[i].base);
1635 }
1636 }
1637 printk("...0x%8.8lx\n", (long) &lp->rx_ring[i].base);
1638 printk("TX: ");
1639 for (i=0;i<lp->txRingMask;i++){
1640 if (i < 3) {
1641 printk("0x%8.8lx ", (long) &lp->tx_ring[i].base);
1642 }
1643 }
1644 printk("...0x%8.8lx\n", (long) &lp->tx_ring[i].base);
1645 printk("\nDescriptor buffers:\nRX: ");
1646 for (i=0;i<lp->rxRingMask;i++){
1647 if (i < 3) {
1648 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1649 }
1650 }
1651 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1652 printk("TX: ");
1653 for (i=0;i<lp->txRingMask;i++){
1654 if (i < 3) {
1655 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1656 }
1657 }
1658 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1659 printk("Initialisation block at 0x%8.8lx\n",lp->sh_mem);
1660 printk("\tmode: 0x%4.4x\n",readw(&p->mode));
1661 printk("\tphysical address: ");
1662 for (i=0;i<ETH_ALEN-1;i++){
1663 printk("%2.2x:",(u_char)readb(&p->phys_addr[i]));
1664 }
1665 printk("%2.2x\n",(u_char)readb(&p->phys_addr[i]));
1666 printk("\tmulticast hash table: ");
1667 for (i=0;i<(HASH_TABLE_LEN >> 3)-1;i++){
1668 printk("%2.2x:",(u_char)readb(&p->mcast_table[i]));
1669 }
1670 printk("%2.2x\n",(u_char)readb(&p->mcast_table[i]));
1671 printk("\trx_ring at: 0x%8.8x\n",readl(&p->rx_ring));
1672 printk("\ttx_ring at: 0x%8.8x\n",readl(&p->tx_ring));
1673 printk("dma_buffs: 0x%8.8lx\n",lp->dma_buffs);
1674 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n",
1675 (int)lp->rxRingMask + 1,
1676 lp->rx_rlen);
1677 printk("TX: %d Log2(txRingMask): 0x%8.8x\n",
1678 (int)lp->txRingMask + 1,
1679 lp->tx_rlen);
1680 outw(CSR2,DEPCA_ADDR);
1681 printk("CSR2&1: 0x%4.4x",inw(DEPCA_DATA));
1682 outw(CSR1,DEPCA_ADDR);
1683 printk("%4.4x\n",inw(DEPCA_DATA));
1684 outw(CSR3,DEPCA_ADDR);
1685 printk("CSR3: 0x%4.4x\n",inw(DEPCA_DATA));
1686 }
1687
1688 return;
1689 }
1690
1691
1692
1693
1694
1695
1696 static int depca_ioctl(struct device *dev, struct ifreq *rq, int cmd)
1697 {
1698 struct depca_private *lp = (struct depca_private *)dev->priv;
1699 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_data;
1700 int i, status = 0;
1701 u_long ioaddr = dev->base_addr;
1702 union {
1703 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1704 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1705 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1706 } tmp;
1707
1708 switch(ioc->cmd) {
1709 case DEPCA_GET_HWADDR:
1710 for (i=0; i<ETH_ALEN; i++) {
1711 tmp.addr[i] = dev->dev_addr[i];
1712 }
1713 ioc->len = ETH_ALEN;
1714 if (!(status = verify_area(VERIFY_WRITE, (void *)ioc->data, ioc->len))) {
1715 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1716 }
1717
1718 break;
1719 case DEPCA_SET_HWADDR:
1720 if (suser()) {
1721 if (!(status = verify_area(VERIFY_READ, (void *)ioc->data, ETH_ALEN))) {
1722 memcpy_fromfs(tmp.addr,ioc->data,ETH_ALEN);
1723 for (i=0; i<ETH_ALEN; i++) {
1724 dev->dev_addr[i] = tmp.addr[i];
1725 }
1726 while(dev->tbusy);
1727 set_bit(0, (void*)&dev->tbusy);
1728 while(lp->tx_old != lp->tx_new);
1729
1730 STOP_DEPCA;
1731 depca_init_ring(dev);
1732 LoadCSRs(dev);
1733 InitRestartDepca(dev);
1734 dev->tbusy = 0;
1735 }
1736 } else {
1737 status = -EPERM;
1738 }
1739
1740 break;
1741 case DEPCA_SET_PROM:
1742 if (suser()) {
1743 while(dev->tbusy);
1744 set_bit(0, (void*)&dev->tbusy);
1745 while(lp->tx_old != lp->tx_new);
1746
1747 STOP_DEPCA;
1748 depca_init_ring(dev);
1749 lp->init_block.mode |= PROM;
1750
1751 LoadCSRs(dev);
1752 InitRestartDepca(dev);
1753 dev->tbusy = 0;
1754 } else {
1755 status = -EPERM;
1756 }
1757
1758 break;
1759 case DEPCA_CLR_PROM:
1760 if (suser()) {
1761 while(dev->tbusy);
1762 set_bit(0, (void*)&dev->tbusy);
1763 while(lp->tx_old != lp->tx_new);
1764
1765 STOP_DEPCA;
1766 depca_init_ring(dev);
1767 lp->init_block.mode &= ~PROM;
1768
1769 LoadCSRs(dev);
1770 InitRestartDepca(dev);
1771 dev->tbusy = 0;
1772 } else {
1773 status = -EPERM;
1774 }
1775
1776 break;
1777 case DEPCA_SAY_BOO:
1778 printk("%s: Boo!\n", dev->name);
1779
1780 break;
1781 case DEPCA_GET_MCA:
1782 ioc->len = (HASH_TABLE_LEN >> 3);
1783 if (!(status = verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1784 memcpy_tofs(ioc->data, lp->init_block.mcast_table, ioc->len);
1785 }
1786
1787 break;
1788 case DEPCA_SET_MCA:
1789 if (suser()) {
1790 if (!(status=verify_area(VERIFY_READ, ioc->data, ETH_ALEN*ioc->len))) {
1791 memcpy_fromfs(tmp.addr, ioc->data, ETH_ALEN * ioc->len);
1792 set_multicast_list(dev);
1793 }
1794 } else {
1795 status = -EPERM;
1796 }
1797
1798 break;
1799 case DEPCA_CLR_MCA:
1800 if (suser()) {
1801 set_multicast_list(dev);
1802 } else {
1803 status = -EPERM;
1804 }
1805
1806 break;
1807 case DEPCA_MCA_EN:
1808 if (suser()) {
1809 set_multicast_list(dev);
1810 } else {
1811 status = -EPERM;
1812 }
1813
1814 break;
1815 case DEPCA_GET_STATS:
1816 cli();
1817 ioc->len = sizeof(lp->pktStats);
1818 if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1819 memcpy_tofs(ioc->data, &lp->pktStats, ioc->len);
1820 }
1821 sti();
1822
1823 break;
1824 case DEPCA_CLR_STATS:
1825 if (suser()) {
1826 cli();
1827 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
1828 sti();
1829 } else {
1830 status = -EPERM;
1831 }
1832
1833 break;
1834 case DEPCA_GET_REG:
1835 i=0;
1836 tmp.sval[i++] = inw(DEPCA_NICSR);
1837 outw(CSR0, DEPCA_ADDR);
1838 tmp.sval[i++] = inw(DEPCA_DATA);
1839 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
1840 ioc->len = i+sizeof(struct depca_init);
1841 if (!(status=verify_area(VERIFY_WRITE, ioc->data, ioc->len))) {
1842 memcpy_tofs(ioc->data, tmp.addr, ioc->len);
1843 }
1844
1845 break;
1846 default:
1847 status = -EOPNOTSUPP;
1848 }
1849
1850 return status;
1851 }
1852
1853 #ifdef MODULE
1854 static char devicename[9] = { 0, };
1855 static struct device thisDepca = {
1856 devicename,
1857 0, 0, 0, 0,
1858 0x200, 7,
1859 0, 0, 0, NULL, depca_probe };
1860
1861 static int irq=7;
1862 static int io=0x200;
1863
1864
1865 int
1866 init_module(void)
1867 {
1868 thisDepca.irq=irq;
1869 thisDepca.base_addr=io;
1870
1871 if (register_netdev(&thisDepca) != 0)
1872 return -EIO;
1873
1874 return 0;
1875 }
1876
1877 void
1878 cleanup_module(void)
1879 {
1880 release_region(thisDepca.base_addr, DEPCA_TOTAL_SIZE);
1881 if (thisDepca.priv) {
1882 kfree(thisDepca.priv);
1883 thisDepca.priv = NULL;
1884 }
1885 thisDepca.irq=0;
1886
1887 unregister_netdev(&thisDepca);
1888 }
1889 #endif
1890
1891
1892
1893
1894
1895
1896
1897
1898