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