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