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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238#include <linux/module.h>
239#include <linux/kernel.h>
240#include <linux/sched.h>
241#include <linux/string.h>
242#include <linux/errno.h>
243#include <linux/ioport.h>
244#include <linux/slab.h>
245#include <linux/interrupt.h>
246#include <linux/delay.h>
247#include <linux/init.h>
248#include <linux/crc32.h>
249#include <linux/netdevice.h>
250#include <linux/etherdevice.h>
251#include <linux/skbuff.h>
252#include <linux/time.h>
253#include <linux/types.h>
254#include <linux/unistd.h>
255#include <linux/ctype.h>
256#include <linux/moduleparam.h>
257#include <linux/platform_device.h>
258#include <linux/bitops.h>
259
260#include <asm/uaccess.h>
261#include <asm/io.h>
262#include <asm/dma.h>
263
264#ifdef CONFIG_MCA
265#include <linux/mca.h>
266#endif
267
268#ifdef CONFIG_EISA
269#include <linux/eisa.h>
270#endif
271
272#include "depca.h"
273
274static char version[] __initdata = "depca.c:v0.53 2001/1/12 davies@maniac.ultranet.com\n";
275
276#ifdef DEPCA_DEBUG
277static int depca_debug = DEPCA_DEBUG;
278#else
279static int depca_debug = 1;
280#endif
281
282#define DEPCA_NDA 0xffe0
283
284#define TX_TIMEOUT (1*HZ)
285
286
287
288
289#define PROBE_LENGTH 32
290#define ETH_PROM_SIG 0xAA5500FFUL
291
292
293
294
295
296
297
298
299#define NUM_RX_DESC 8
300#define NUM_TX_DESC 8
301#define RX_BUFF_SZ 1536
302#define TX_BUFF_SZ 1536
303
304
305
306
307#define DEPCA_EISA_IO_PORTS 0x0c00
308
309
310
311
312#define DEPCA_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0xe0000,0x00000}
313#define DEPCA_TOTAL_SIZE 0x10
314
315static struct {
316 u_long iobase;
317 struct platform_device *device;
318} depca_io_ports[] = {
319 { 0x300, NULL },
320 { 0x200, NULL },
321 { 0 , NULL },
322};
323
324
325
326
327#define DEPCA_SIGNATURE {"DEPCA",\
328 "DE100","DE101",\
329 "DE200","DE201","DE202",\
330 "DE210","DE212",\
331 "DE422",\
332 ""}
333
334static char* __initdata depca_signature[] = DEPCA_SIGNATURE;
335
336enum depca_type {
337 DEPCA, de100, de101, de200, de201, de202, de210, de212, de422, unknown
338};
339
340static char depca_string[] = "depca";
341
342static int depca_device_remove (struct device *device);
343
344#ifdef CONFIG_EISA
345static struct eisa_device_id depca_eisa_ids[] = {
346 { "DEC4220", de422 },
347 { "" }
348};
349MODULE_DEVICE_TABLE(eisa, depca_eisa_ids);
350
351static int depca_eisa_probe (struct device *device);
352
353static struct eisa_driver depca_eisa_driver = {
354 .id_table = depca_eisa_ids,
355 .driver = {
356 .name = depca_string,
357 .probe = depca_eisa_probe,
358 .remove = __devexit_p (depca_device_remove)
359 }
360};
361#endif
362
363#ifdef CONFIG_MCA
364
365
366
367#define DE210_ID 0x628d
368#define DE212_ID 0x6def
369
370static short depca_mca_adapter_ids[] = {
371 DE210_ID,
372 DE212_ID,
373 0x0000
374};
375
376static char *depca_mca_adapter_name[] = {
377 "DEC EtherWORKS MC Adapter (DE210)",
378 "DEC EtherWORKS MC Adapter (DE212)",
379 NULL
380};
381
382static enum depca_type depca_mca_adapter_type[] = {
383 de210,
384 de212,
385 0
386};
387
388static int depca_mca_probe (struct device *);
389
390static struct mca_driver depca_mca_driver = {
391 .id_table = depca_mca_adapter_ids,
392 .driver = {
393 .name = depca_string,
394 .bus = &mca_bus_type,
395 .probe = depca_mca_probe,
396 .remove = __devexit_p(depca_device_remove),
397 },
398};
399#endif
400
401static int depca_isa_probe (struct platform_device *);
402
403static int __devexit depca_isa_remove(struct platform_device *pdev)
404{
405 return depca_device_remove(&pdev->dev);
406}
407
408static struct platform_driver depca_isa_driver = {
409 .probe = depca_isa_probe,
410 .remove = __devexit_p(depca_isa_remove),
411 .driver = {
412 .name = depca_string,
413 },
414};
415
416
417
418
419#define DEPCA_STRLEN 16
420
421
422
423
424
425
426
427#define DEPCA_ALIGN4 ((u_long)4 - 1)
428#define DEPCA_ALIGN8 ((u_long)8 - 1)
429#define DEPCA_ALIGN DEPCA_ALIGN8
430
431
432
433
434struct depca_rx_desc {
435 volatile s32 base;
436 s16 buf_length;
437 s16 msg_length;
438};
439
440struct depca_tx_desc {
441 volatile s32 base;
442 s16 length;
443 s16 misc;
444};
445
446#define LA_MASK 0x0000ffff
447
448
449
450
451
452struct depca_init {
453 u16 mode;
454 u8 phys_addr[ETH_ALEN];
455 u8 mcast_table[8];
456 u32 rx_ring;
457 u32 tx_ring;
458};
459
460#define DEPCA_PKT_STAT_SZ 16
461#define DEPCA_PKT_BIN_SZ 128
462
463struct depca_private {
464 char adapter_name[DEPCA_STRLEN];
465 enum depca_type adapter;
466 enum {
467 DEPCA_BUS_MCA = 1,
468 DEPCA_BUS_ISA,
469 DEPCA_BUS_EISA,
470 } depca_bus;
471 struct depca_init init_block;
472
473 struct depca_rx_desc __iomem *rx_ring;
474 struct depca_tx_desc __iomem *tx_ring;
475 void __iomem *rx_buff[NUM_RX_DESC];
476 void __iomem *tx_buff[NUM_TX_DESC];
477 void __iomem *sh_mem;
478 u_long mem_start;
479 u_long mem_len;
480
481 u_long device_ram_start;
482
483 u_long rx_ring_offset;
484 u_long tx_ring_offset;
485 u_long buffs_offset;
486
487 int rx_new, tx_new;
488 int rx_old, tx_old;
489 spinlock_t lock;
490 struct {
491 u32 bins[DEPCA_PKT_STAT_SZ];
492 u32 unicast;
493 u32 multicast;
494 u32 broadcast;
495 u32 excessive_collisions;
496 u32 tx_underruns;
497 u32 excessive_underruns;
498 } pktStats;
499 int txRingMask;
500 int rxRingMask;
501 s32 rx_rlen;
502 s32 tx_rlen;
503};
504
505
506
507
508
509
510
511
512#define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
513 lp->tx_old+lp->txRingMask-lp->tx_new:\
514 lp->tx_old -lp->tx_new-1)
515
516
517
518
519static int depca_open(struct net_device *dev);
520static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
521 struct net_device *dev);
522static irqreturn_t depca_interrupt(int irq, void *dev_id);
523static int depca_close(struct net_device *dev);
524static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
525static void depca_tx_timeout(struct net_device *dev);
526static void set_multicast_list(struct net_device *dev);
527
528
529
530
531static void depca_init_ring(struct net_device *dev);
532static int depca_rx(struct net_device *dev);
533static int depca_tx(struct net_device *dev);
534
535static void LoadCSRs(struct net_device *dev);
536static int InitRestartDepca(struct net_device *dev);
537static int DepcaSignature(char *name, u_long paddr);
538static int DevicePresent(u_long ioaddr);
539static int get_hw_addr(struct net_device *dev);
540static void SetMulticastFilter(struct net_device *dev);
541static int load_packet(struct net_device *dev, struct sk_buff *skb);
542static void depca_dbg_open(struct net_device *dev);
543
544static u_char de1xx_irq[] __initdata = { 2, 3, 4, 5, 7, 9, 0 };
545static u_char de2xx_irq[] __initdata = { 5, 9, 10, 11, 15, 0 };
546static u_char de422_irq[] __initdata = { 5, 9, 10, 11, 0 };
547static u_char *depca_irq;
548
549static int irq;
550static int io;
551static char *adapter_name;
552static int mem;
553
554module_param (irq, int, 0);
555module_param (io, int, 0);
556module_param (adapter_name, charp, 0);
557module_param (mem, int, 0);
558MODULE_PARM_DESC(irq, "DEPCA IRQ number");
559MODULE_PARM_DESC(io, "DEPCA I/O base address");
560MODULE_PARM_DESC(adapter_name, "DEPCA adapter name");
561MODULE_PARM_DESC(mem, "DEPCA shared memory address");
562MODULE_LICENSE("GPL");
563
564
565
566
567#define STOP_DEPCA \
568 outw(CSR0, DEPCA_ADDR);\
569 outw(STOP, DEPCA_DATA)
570
571static const struct net_device_ops depca_netdev_ops = {
572 .ndo_open = depca_open,
573 .ndo_start_xmit = depca_start_xmit,
574 .ndo_stop = depca_close,
575 .ndo_set_multicast_list = set_multicast_list,
576 .ndo_do_ioctl = depca_ioctl,
577 .ndo_tx_timeout = depca_tx_timeout,
578 .ndo_change_mtu = eth_change_mtu,
579 .ndo_set_mac_address = eth_mac_addr,
580 .ndo_validate_addr = eth_validate_addr,
581};
582
583static int __init depca_hw_init (struct net_device *dev, struct device *device)
584{
585 struct depca_private *lp;
586 int i, j, offset, netRAM, mem_len, status = 0;
587 s16 nicsr;
588 u_long ioaddr;
589 u_long mem_start;
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605 ioaddr = dev->base_addr;
606
607 STOP_DEPCA;
608
609 nicsr = inb(DEPCA_NICSR);
610 nicsr = ((nicsr & ~SHE & ~RBE & ~IEN) | IM);
611 outb(nicsr, DEPCA_NICSR);
612
613 if (inw(DEPCA_DATA) != STOP) {
614 return -ENXIO;
615 }
616
617 lp = netdev_priv(dev);
618 mem_start = lp->mem_start;
619
620 if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown)
621 return -ENXIO;
622
623 printk("%s: %s at 0x%04lx",
624 dev_name(device), depca_signature[lp->adapter], ioaddr);
625
626 switch (lp->depca_bus) {
627#ifdef CONFIG_MCA
628 case DEPCA_BUS_MCA:
629 printk(" (MCA slot %d)", to_mca_device(device)->slot + 1);
630 break;
631#endif
632
633#ifdef CONFIG_EISA
634 case DEPCA_BUS_EISA:
635 printk(" (EISA slot %d)", to_eisa_device(device)->slot);
636 break;
637#endif
638
639 case DEPCA_BUS_ISA:
640 break;
641
642 default:
643 printk("Unknown DEPCA bus %d\n", lp->depca_bus);
644 return -ENXIO;
645 }
646
647 printk(", h/w address ");
648 status = get_hw_addr(dev);
649 printk("%pM", dev->dev_addr);
650 if (status != 0) {
651 printk(" which has an Ethernet PROM CRC error.\n");
652 return -ENXIO;
653 }
654
655
656 netRAM = ((lp->adapter != DEPCA) ? 64 : 48);
657 if ((nicsr & _128KB) && (lp->adapter == de422))
658 netRAM = 128;
659
660
661 if (nicsr & BUF) {
662 nicsr &= ~BS;
663 netRAM -= 32;
664
665
666 if (lp->depca_bus != DEPCA_BUS_MCA)
667 mem_start += 0x8000;
668 }
669
670 if ((mem_len = (NUM_RX_DESC * (sizeof(struct depca_rx_desc) + RX_BUFF_SZ) + NUM_TX_DESC * (sizeof(struct depca_tx_desc) + TX_BUFF_SZ) + sizeof(struct depca_init)))
671 > (netRAM << 10)) {
672 printk(",\n requests %dkB RAM: only %dkB is available!\n", (mem_len >> 10), netRAM);
673 return -ENXIO;
674 }
675
676 printk(",\n has %dkB RAM at 0x%.5lx", netRAM, mem_start);
677
678
679 if (lp->adapter != DEPCA) {
680 nicsr |= SHE;
681 outb(nicsr, DEPCA_NICSR);
682 }
683
684 spin_lock_init(&lp->lock);
685 sprintf(lp->adapter_name, "%s (%s)",
686 depca_signature[lp->adapter], dev_name(device));
687 status = -EBUSY;
688
689
690 if (!request_mem_region (mem_start, mem_len, lp->adapter_name)) {
691 printk(KERN_ERR "depca: cannot request ISA memory, aborting\n");
692 goto out_priv;
693 }
694
695 status = -EIO;
696 lp->sh_mem = ioremap(mem_start, mem_len);
697 if (lp->sh_mem == NULL) {
698 printk(KERN_ERR "depca: cannot remap ISA memory, aborting\n");
699 goto out1;
700 }
701
702 lp->mem_start = mem_start;
703 lp->mem_len = mem_len;
704 lp->device_ram_start = mem_start & LA_MASK;
705
706 offset = 0;
707 offset += sizeof(struct depca_init);
708
709
710 offset = (offset + DEPCA_ALIGN) & ~DEPCA_ALIGN;
711 lp->rx_ring = (struct depca_rx_desc __iomem *) (lp->sh_mem + offset);
712 lp->rx_ring_offset = offset;
713
714 offset += (sizeof(struct depca_rx_desc) * NUM_RX_DESC);
715 lp->tx_ring = (struct depca_tx_desc __iomem *) (lp->sh_mem + offset);
716 lp->tx_ring_offset = offset;
717
718 offset += (sizeof(struct depca_tx_desc) * NUM_TX_DESC);
719
720 lp->buffs_offset = offset;
721
722
723 lp->rxRingMask = NUM_RX_DESC - 1;
724 lp->txRingMask = NUM_TX_DESC - 1;
725
726
727 for (i = 0, j = lp->rxRingMask; j > 0; i++) {
728 j >>= 1;
729 }
730 lp->rx_rlen = (s32) (i << 29);
731 for (i = 0, j = lp->txRingMask; j > 0; i++) {
732 j >>= 1;
733 }
734 lp->tx_rlen = (s32) (i << 29);
735
736
737 depca_init_ring(dev);
738
739
740 LoadCSRs(dev);
741
742
743 nicsr = ((nicsr & ~IM) | IEN);
744 outb(nicsr, DEPCA_NICSR);
745
746
747
748 if (dev->irq < 2) {
749 unsigned char irqnum;
750 unsigned long irq_mask, delay;
751
752 irq_mask = probe_irq_on();
753
754
755 switch (lp->adapter) {
756 case DEPCA:
757 case de100:
758 case de101:
759 depca_irq = de1xx_irq;
760 break;
761 case de200:
762 case de201:
763 case de202:
764 case de210:
765 case de212:
766 depca_irq = de2xx_irq;
767 break;
768 case de422:
769 depca_irq = de422_irq;
770 break;
771
772 default:
773 break;
774 }
775
776
777 outw(INEA | INIT, DEPCA_DATA);
778
779 delay = jiffies + HZ/50;
780 while (time_before(jiffies, delay))
781 yield();
782
783 irqnum = probe_irq_off(irq_mask);
784
785 status = -ENXIO;
786 if (!irqnum) {
787 printk(" and failed to detect IRQ line.\n");
788 goto out2;
789 } else {
790 for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
791 if (irqnum == depca_irq[i]) {
792 dev->irq = irqnum;
793 printk(" and uses IRQ%d.\n", dev->irq);
794 }
795
796 if (!dev->irq) {
797 printk(" but incorrect IRQ line detected.\n");
798 goto out2;
799 }
800 }
801 } else {
802 printk(" and assigned IRQ%d.\n", dev->irq);
803 }
804
805 if (depca_debug > 1) {
806 printk(version);
807 }
808
809
810 dev->netdev_ops = &depca_netdev_ops;
811 dev->watchdog_timeo = TX_TIMEOUT;
812
813 dev->mem_start = 0;
814
815 dev_set_drvdata(device, dev);
816 SET_NETDEV_DEV (dev, device);
817
818 status = register_netdev(dev);
819 if (status == 0)
820 return 0;
821out2:
822 iounmap(lp->sh_mem);
823out1:
824 release_mem_region (mem_start, mem_len);
825out_priv:
826 return status;
827}
828
829
830static int depca_open(struct net_device *dev)
831{
832 struct depca_private *lp = netdev_priv(dev);
833 u_long ioaddr = dev->base_addr;
834 s16 nicsr;
835 int status = 0;
836
837 STOP_DEPCA;
838 nicsr = inb(DEPCA_NICSR);
839
840
841 if (lp->adapter != DEPCA) {
842 nicsr |= SHE;
843 outb(nicsr, DEPCA_NICSR);
844 }
845
846
847 depca_init_ring(dev);
848 LoadCSRs(dev);
849
850 depca_dbg_open(dev);
851
852 if (request_irq(dev->irq, depca_interrupt, 0, lp->adapter_name, dev)) {
853 printk("depca_open(): Requested IRQ%d is busy\n", dev->irq);
854 status = -EAGAIN;
855 } else {
856
857
858 nicsr = ((nicsr & ~IM & ~LED) | IEN);
859 outb(nicsr, DEPCA_NICSR);
860 outw(CSR0, DEPCA_ADDR);
861
862 netif_start_queue(dev);
863
864 status = InitRestartDepca(dev);
865
866 if (depca_debug > 1) {
867 printk("CSR0: 0x%4.4x\n", inw(DEPCA_DATA));
868 printk("nicsr: 0x%02x\n", inb(DEPCA_NICSR));
869 }
870 }
871 return status;
872}
873
874
875static void depca_init_ring(struct net_device *dev)
876{
877 struct depca_private *lp = netdev_priv(dev);
878 u_int i;
879 u_long offset;
880
881
882 netif_stop_queue(dev);
883
884 lp->rx_new = lp->tx_new = 0;
885 lp->rx_old = lp->tx_old = 0;
886
887
888 for (i = 0; i <= lp->rxRingMask; i++) {
889 offset = lp->buffs_offset + i * RX_BUFF_SZ;
890 writel((lp->device_ram_start + offset) | R_OWN, &lp->rx_ring[i].base);
891 writew(-RX_BUFF_SZ, &lp->rx_ring[i].buf_length);
892 lp->rx_buff[i] = lp->sh_mem + offset;
893 }
894
895 for (i = 0; i <= lp->txRingMask; i++) {
896 offset = lp->buffs_offset + (i + lp->rxRingMask + 1) * TX_BUFF_SZ;
897 writel((lp->device_ram_start + offset) & 0x00ffffff, &lp->tx_ring[i].base);
898 lp->tx_buff[i] = lp->sh_mem + offset;
899 }
900
901
902 lp->init_block.rx_ring = (lp->device_ram_start + lp->rx_ring_offset) | lp->rx_rlen;
903 lp->init_block.tx_ring = (lp->device_ram_start + lp->tx_ring_offset) | lp->tx_rlen;
904
905 SetMulticastFilter(dev);
906
907 for (i = 0; i < ETH_ALEN; i++) {
908 lp->init_block.phys_addr[i] = dev->dev_addr[i];
909 }
910
911 lp->init_block.mode = 0x0000;
912}
913
914
915static void depca_tx_timeout(struct net_device *dev)
916{
917 u_long ioaddr = dev->base_addr;
918
919 printk("%s: transmit timed out, status %04x, resetting.\n", dev->name, inw(DEPCA_DATA));
920
921 STOP_DEPCA;
922 depca_init_ring(dev);
923 LoadCSRs(dev);
924 dev->trans_start = jiffies;
925 netif_wake_queue(dev);
926 InitRestartDepca(dev);
927}
928
929
930
931
932
933static netdev_tx_t depca_start_xmit(struct sk_buff *skb,
934 struct net_device *dev)
935{
936 struct depca_private *lp = netdev_priv(dev);
937 u_long ioaddr = dev->base_addr;
938 int status = 0;
939
940
941 if (skb->len < 1)
942 goto out;
943
944 if (skb_padto(skb, ETH_ZLEN))
945 goto out;
946
947 netif_stop_queue(dev);
948
949 if (TX_BUFFS_AVAIL) {
950 status = load_packet(dev, skb);
951
952 if (!status) {
953
954 outw(CSR0, DEPCA_ADDR);
955 outw(INEA | TDMD, DEPCA_DATA);
956
957 dev_kfree_skb(skb);
958 }
959 if (TX_BUFFS_AVAIL)
960 netif_start_queue(dev);
961 } else
962 status = NETDEV_TX_LOCKED;
963
964 out:
965 return status;
966}
967
968
969
970
971static irqreturn_t depca_interrupt(int irq, void *dev_id)
972{
973 struct net_device *dev = dev_id;
974 struct depca_private *lp;
975 s16 csr0, nicsr;
976 u_long ioaddr;
977
978 if (dev == NULL) {
979 printk("depca_interrupt(): irq %d for unknown device.\n", irq);
980 return IRQ_NONE;
981 }
982
983 lp = netdev_priv(dev);
984 ioaddr = dev->base_addr;
985
986 spin_lock(&lp->lock);
987
988
989 nicsr = inb(DEPCA_NICSR);
990 nicsr |= (IM | LED);
991 outb(nicsr, DEPCA_NICSR);
992
993 outw(CSR0, DEPCA_ADDR);
994 csr0 = inw(DEPCA_DATA);
995
996
997 outw(csr0 & INTE, DEPCA_DATA);
998
999 if (csr0 & RINT)
1000 depca_rx(dev);
1001
1002 if (csr0 & TINT)
1003 depca_tx(dev);
1004
1005
1006 if ((TX_BUFFS_AVAIL >= 0) && netif_queue_stopped(dev)) {
1007 netif_wake_queue(dev);
1008 }
1009
1010
1011 nicsr = (nicsr & ~IM & ~LED);
1012 outb(nicsr, DEPCA_NICSR);
1013
1014 spin_unlock(&lp->lock);
1015 return IRQ_HANDLED;
1016}
1017
1018
1019static int depca_rx(struct net_device *dev)
1020{
1021 struct depca_private *lp = netdev_priv(dev);
1022 int i, entry;
1023 s32 status;
1024
1025 for (entry = lp->rx_new; !(readl(&lp->rx_ring[entry].base) & R_OWN); entry = lp->rx_new) {
1026 status = readl(&lp->rx_ring[entry].base) >> 16;
1027 if (status & R_STP) {
1028 lp->rx_old = entry;
1029 }
1030 if (status & R_ENP) {
1031 if (status & R_ERR) {
1032 dev->stats.rx_errors++;
1033 if (status & R_FRAM)
1034 dev->stats.rx_frame_errors++;
1035 if (status & R_OFLO)
1036 dev->stats.rx_over_errors++;
1037 if (status & R_CRC)
1038 dev->stats.rx_crc_errors++;
1039 if (status & R_BUFF)
1040 dev->stats.rx_fifo_errors++;
1041 } else {
1042 short len, pkt_len = readw(&lp->rx_ring[entry].msg_length) - 4;
1043 struct sk_buff *skb;
1044
1045 skb = dev_alloc_skb(pkt_len + 2);
1046 if (skb != NULL) {
1047 unsigned char *buf;
1048 skb_reserve(skb, 2);
1049 buf = skb_put(skb, pkt_len);
1050 if (entry < lp->rx_old) {
1051 len = (lp->rxRingMask - lp->rx_old + 1) * RX_BUFF_SZ;
1052 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], len);
1053 memcpy_fromio(buf + len, lp->rx_buff[0], pkt_len - len);
1054 } else {
1055 memcpy_fromio(buf, lp->rx_buff[lp->rx_old], pkt_len);
1056 }
1057
1058
1059
1060
1061
1062 skb->protocol = eth_type_trans(skb, dev);
1063 netif_rx(skb);
1064
1065
1066
1067
1068 dev->stats.rx_packets++;
1069 dev->stats.rx_bytes += pkt_len;
1070 for (i = 1; i < DEPCA_PKT_STAT_SZ - 1; i++) {
1071 if (pkt_len < (i * DEPCA_PKT_BIN_SZ)) {
1072 lp->pktStats.bins[i]++;
1073 i = DEPCA_PKT_STAT_SZ;
1074 }
1075 }
1076 if (buf[0] & 0x01) {
1077 if ((*(s16 *) & buf[0] == -1) && (*(s16 *) & buf[2] == -1) && (*(s16 *) & buf[4] == -1)) {
1078 lp->pktStats.broadcast++;
1079 } else {
1080 lp->pktStats.multicast++;
1081 }
1082 } else if ((*(s16 *) & buf[0] == *(s16 *) & dev->dev_addr[0]) && (*(s16 *) & buf[2] == *(s16 *) & dev->dev_addr[2]) && (*(s16 *) & buf[4] == *(s16 *) & dev->dev_addr[4])) {
1083 lp->pktStats.unicast++;
1084 }
1085
1086 lp->pktStats.bins[0]++;
1087 if (lp->pktStats.bins[0] == 0) {
1088 memset((char *) &lp->pktStats, 0, sizeof(lp->pktStats));
1089 }
1090 } else {
1091 printk("%s: Memory squeeze, deferring packet.\n", dev->name);
1092 dev->stats.rx_dropped++;
1093 break;
1094 }
1095 }
1096
1097 for (; lp->rx_old != entry; lp->rx_old = (lp->rx_old + 1) & lp->rxRingMask) {
1098 writel(readl(&lp->rx_ring[lp->rx_old].base) | R_OWN, &lp->rx_ring[lp->rx_old].base);
1099 }
1100 writel(readl(&lp->rx_ring[entry].base) | R_OWN, &lp->rx_ring[entry].base);
1101 }
1102
1103
1104
1105
1106 lp->rx_new = (lp->rx_new + 1) & lp->rxRingMask;
1107 }
1108
1109 return 0;
1110}
1111
1112
1113
1114
1115
1116static int depca_tx(struct net_device *dev)
1117{
1118 struct depca_private *lp = netdev_priv(dev);
1119 int entry;
1120 s32 status;
1121 u_long ioaddr = dev->base_addr;
1122
1123 for (entry = lp->tx_old; entry != lp->tx_new; entry = lp->tx_old) {
1124 status = readl(&lp->tx_ring[entry].base) >> 16;
1125
1126 if (status < 0) {
1127 break;
1128 } else if (status & T_ERR) {
1129 status = readl(&lp->tx_ring[entry].misc);
1130 dev->stats.tx_errors++;
1131 if (status & TMD3_RTRY)
1132 dev->stats.tx_aborted_errors++;
1133 if (status & TMD3_LCAR)
1134 dev->stats.tx_carrier_errors++;
1135 if (status & TMD3_LCOL)
1136 dev->stats.tx_window_errors++;
1137 if (status & TMD3_UFLO)
1138 dev->stats.tx_fifo_errors++;
1139 if (status & (TMD3_BUFF | TMD3_UFLO)) {
1140
1141 outw(CSR0, DEPCA_ADDR);
1142 outw(INEA | TDMD, DEPCA_DATA);
1143 }
1144 } else if (status & (T_MORE | T_ONE)) {
1145 dev->stats.collisions++;
1146 } else {
1147 dev->stats.tx_packets++;
1148 }
1149
1150
1151 lp->tx_old = (lp->tx_old + 1) & lp->txRingMask;
1152 }
1153
1154 return 0;
1155}
1156
1157static int depca_close(struct net_device *dev)
1158{
1159 struct depca_private *lp = netdev_priv(dev);
1160 s16 nicsr;
1161 u_long ioaddr = dev->base_addr;
1162
1163 netif_stop_queue(dev);
1164
1165 outw(CSR0, DEPCA_ADDR);
1166
1167 if (depca_debug > 1) {
1168 printk("%s: Shutting down ethercard, status was %2.2x.\n", dev->name, inw(DEPCA_DATA));
1169 }
1170
1171
1172
1173
1174
1175 outw(STOP, DEPCA_DATA);
1176
1177
1178
1179
1180 if (lp->adapter != DEPCA) {
1181 nicsr = inb(DEPCA_NICSR);
1182 nicsr &= ~SHE;
1183 outb(nicsr, DEPCA_NICSR);
1184 }
1185
1186
1187
1188
1189 free_irq(dev->irq, dev);
1190 return 0;
1191}
1192
1193static void LoadCSRs(struct net_device *dev)
1194{
1195 struct depca_private *lp = netdev_priv(dev);
1196 u_long ioaddr = dev->base_addr;
1197
1198 outw(CSR1, DEPCA_ADDR);
1199 outw((u16) lp->device_ram_start, DEPCA_DATA);
1200 outw(CSR2, DEPCA_ADDR);
1201 outw((u16) (lp->device_ram_start >> 16), DEPCA_DATA);
1202 outw(CSR3, DEPCA_ADDR);
1203 outw(ACON, DEPCA_DATA);
1204
1205 outw(CSR0, DEPCA_ADDR);
1206}
1207
1208static int InitRestartDepca(struct net_device *dev)
1209{
1210 struct depca_private *lp = netdev_priv(dev);
1211 u_long ioaddr = dev->base_addr;
1212 int i, status = 0;
1213
1214
1215 memcpy_toio(lp->sh_mem, &lp->init_block, sizeof(struct depca_init));
1216
1217 outw(CSR0, DEPCA_ADDR);
1218 outw(INIT, DEPCA_DATA);
1219
1220
1221 for (i = 0; (i < 100) && !(inw(DEPCA_DATA) & IDON); i++);
1222
1223 if (i != 100) {
1224
1225 outw(IDON | INEA | STRT, DEPCA_DATA);
1226 if (depca_debug > 2) {
1227 printk("%s: DEPCA open after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
1228 }
1229 } else {
1230 printk("%s: DEPCA unopen after %d ticks, init block 0x%08lx csr0 %4.4x.\n", dev->name, i, lp->mem_start, inw(DEPCA_DATA));
1231 status = -1;
1232 }
1233
1234 return status;
1235}
1236
1237
1238
1239
1240static void set_multicast_list(struct net_device *dev)
1241{
1242 struct depca_private *lp = netdev_priv(dev);
1243 u_long ioaddr = dev->base_addr;
1244
1245 netif_stop_queue(dev);
1246 while (lp->tx_old != lp->tx_new);
1247
1248 STOP_DEPCA;
1249 depca_init_ring(dev);
1250
1251 if (dev->flags & IFF_PROMISC) {
1252 lp->init_block.mode |= PROM;
1253 } else {
1254 SetMulticastFilter(dev);
1255 lp->init_block.mode &= ~PROM;
1256 }
1257
1258 LoadCSRs(dev);
1259 InitRestartDepca(dev);
1260 netif_start_queue(dev);
1261}
1262
1263
1264
1265
1266
1267
1268
1269static void SetMulticastFilter(struct net_device *dev)
1270{
1271 struct depca_private *lp = netdev_priv(dev);
1272 struct netdev_hw_addr *ha;
1273 char *addrs;
1274 int i, j, bit, byte;
1275 u16 hashcode;
1276 u32 crc;
1277
1278 if (dev->flags & IFF_ALLMULTI) {
1279 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1280 lp->init_block.mcast_table[i] = (char) 0xff;
1281 }
1282 } else {
1283 for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
1284 lp->init_block.mcast_table[i] = 0;
1285 }
1286
1287 netdev_for_each_mc_addr(ha, dev) {
1288 addrs = ha->addr;
1289 if ((*addrs & 0x01) == 1) {
1290 crc = ether_crc(ETH_ALEN, addrs);
1291 hashcode = (crc & 1);
1292 for (j = 0; j < 5; j++) {
1293 hashcode = (hashcode << 1) | ((crc >>= 1) & 1);
1294 }
1295
1296
1297 byte = hashcode >> 3;
1298 bit = 1 << (hashcode & 0x07);
1299 lp->init_block.mcast_table[byte] |= bit;
1300 }
1301 }
1302 }
1303}
1304
1305static int __init depca_common_init (u_long ioaddr, struct net_device **devp)
1306{
1307 int status = 0;
1308
1309 if (!request_region (ioaddr, DEPCA_TOTAL_SIZE, depca_string)) {
1310 status = -EBUSY;
1311 goto out;
1312 }
1313
1314 if (DevicePresent(ioaddr)) {
1315 status = -ENODEV;
1316 goto out_release;
1317 }
1318
1319 if (!(*devp = alloc_etherdev (sizeof (struct depca_private)))) {
1320 status = -ENOMEM;
1321 goto out_release;
1322 }
1323
1324 return 0;
1325
1326 out_release:
1327 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1328 out:
1329 return status;
1330}
1331
1332#ifdef CONFIG_MCA
1333
1334
1335
1336static int __init depca_mca_probe(struct device *device)
1337{
1338 unsigned char pos[2];
1339 unsigned char where;
1340 unsigned long iobase, mem_start;
1341 int irq, err;
1342 struct mca_device *mdev = to_mca_device (device);
1343 struct net_device *dev;
1344 struct depca_private *lp;
1345
1346
1347
1348
1349
1350
1351
1352 pos[0] = mca_device_read_stored_pos(mdev, 2);
1353 pos[1] = mca_device_read_stored_pos(mdev, 3);
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364 where = (pos[0] & 6) >> 1;
1365 iobase = 0x2c00 + (0x10 * where);
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381 where = pos[1] & 0x0f;
1382 switch (where) {
1383 case 1:
1384 irq = 9;
1385 break;
1386 case 2:
1387 irq = 5;
1388 break;
1389 case 4:
1390 irq = 10;
1391 break;
1392 case 8:
1393 irq = 11;
1394 break;
1395 default:
1396 printk("%s: mca_probe IRQ error. You should never get here (%d).\n", mdev->name, where);
1397 return -EINVAL;
1398 }
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413 where = (pos[0] & 0x18) >> 3;
1414 mem_start = 0xc0000 + (where * 0x10000);
1415 if (pos[0] & 0x20) {
1416 mem_start += 0x8000;
1417 }
1418
1419
1420 strncpy(mdev->name, depca_mca_adapter_name[mdev->index],
1421 sizeof(mdev->name));
1422 mca_device_set_claim(mdev, 1);
1423
1424
1425
1426
1427
1428 irq = mca_device_transform_irq(mdev, irq);
1429 iobase = mca_device_transform_ioport(mdev, iobase);
1430
1431 if ((err = depca_common_init (iobase, &dev)))
1432 goto out_unclaim;
1433
1434 dev->irq = irq;
1435 dev->base_addr = iobase;
1436 lp = netdev_priv(dev);
1437 lp->depca_bus = DEPCA_BUS_MCA;
1438 lp->adapter = depca_mca_adapter_type[mdev->index];
1439 lp->mem_start = mem_start;
1440
1441 if ((err = depca_hw_init(dev, device)))
1442 goto out_free;
1443
1444 return 0;
1445
1446 out_free:
1447 free_netdev (dev);
1448 release_region (iobase, DEPCA_TOTAL_SIZE);
1449 out_unclaim:
1450 mca_device_set_claim(mdev, 0);
1451
1452 return err;
1453}
1454#endif
1455
1456
1457
1458
1459
1460static void __init depca_platform_probe (void)
1461{
1462 int i;
1463 struct platform_device *pldev;
1464
1465 for (i = 0; depca_io_ports[i].iobase; i++) {
1466 depca_io_ports[i].device = NULL;
1467
1468
1469
1470 if (io && io != depca_io_ports[i].iobase)
1471 continue;
1472
1473 pldev = platform_device_alloc(depca_string, i);
1474 if (!pldev)
1475 continue;
1476
1477 pldev->dev.platform_data = (void *) depca_io_ports[i].iobase;
1478 depca_io_ports[i].device = pldev;
1479
1480 if (platform_device_add(pldev)) {
1481 depca_io_ports[i].device = NULL;
1482 pldev->dev.platform_data = NULL;
1483 platform_device_put(pldev);
1484 continue;
1485 }
1486
1487 if (!pldev->dev.driver) {
1488
1489
1490
1491
1492
1493 depca_io_ports[i].device = NULL;
1494 pldev->dev.platform_data = NULL;
1495 platform_device_unregister (pldev);
1496 }
1497 }
1498}
1499
1500static enum depca_type __init depca_shmem_probe (ulong *mem_start)
1501{
1502 u_long mem_base[] = DEPCA_RAM_BASE_ADDRESSES;
1503 enum depca_type adapter = unknown;
1504 int i;
1505
1506 for (i = 0; mem_base[i]; i++) {
1507 *mem_start = mem ? mem : mem_base[i];
1508 adapter = DepcaSignature (adapter_name, *mem_start);
1509 if (adapter != unknown)
1510 break;
1511 }
1512
1513 return adapter;
1514}
1515
1516static int __devinit depca_isa_probe (struct platform_device *device)
1517{
1518 struct net_device *dev;
1519 struct depca_private *lp;
1520 u_long ioaddr, mem_start = 0;
1521 enum depca_type adapter = unknown;
1522 int status = 0;
1523
1524 ioaddr = (u_long) device->dev.platform_data;
1525
1526 if ((status = depca_common_init (ioaddr, &dev)))
1527 goto out;
1528
1529 adapter = depca_shmem_probe (&mem_start);
1530
1531 if (adapter == unknown) {
1532 status = -ENODEV;
1533 goto out_free;
1534 }
1535
1536 dev->base_addr = ioaddr;
1537 dev->irq = irq;
1538
1539 lp = netdev_priv(dev);
1540 lp->depca_bus = DEPCA_BUS_ISA;
1541 lp->adapter = adapter;
1542 lp->mem_start = mem_start;
1543
1544 if ((status = depca_hw_init(dev, &device->dev)))
1545 goto out_free;
1546
1547 return 0;
1548
1549 out_free:
1550 free_netdev (dev);
1551 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1552 out:
1553 return status;
1554}
1555
1556
1557
1558
1559
1560#ifdef CONFIG_EISA
1561static int __init depca_eisa_probe (struct device *device)
1562{
1563 enum depca_type adapter = unknown;
1564 struct eisa_device *edev;
1565 struct net_device *dev;
1566 struct depca_private *lp;
1567 u_long ioaddr, mem_start;
1568 int status = 0;
1569
1570 edev = to_eisa_device (device);
1571 ioaddr = edev->base_addr + DEPCA_EISA_IO_PORTS;
1572
1573 if ((status = depca_common_init (ioaddr, &dev)))
1574 goto out;
1575
1576
1577
1578
1579
1580
1581
1582 adapter = depca_shmem_probe (&mem_start);
1583 if (adapter == unknown) {
1584 status = -ENODEV;
1585 goto out_free;
1586 }
1587
1588 dev->base_addr = ioaddr;
1589 dev->irq = irq;
1590 lp = netdev_priv(dev);
1591 lp->depca_bus = DEPCA_BUS_EISA;
1592 lp->adapter = edev->id.driver_data;
1593 lp->mem_start = mem_start;
1594
1595 if ((status = depca_hw_init(dev, device)))
1596 goto out_free;
1597
1598 return 0;
1599
1600 out_free:
1601 free_netdev (dev);
1602 release_region (ioaddr, DEPCA_TOTAL_SIZE);
1603 out:
1604 return status;
1605}
1606#endif
1607
1608static int __devexit depca_device_remove (struct device *device)
1609{
1610 struct net_device *dev;
1611 struct depca_private *lp;
1612 int bus;
1613
1614 dev = dev_get_drvdata(device);
1615 lp = netdev_priv(dev);
1616
1617 unregister_netdev (dev);
1618 iounmap (lp->sh_mem);
1619 release_mem_region (lp->mem_start, lp->mem_len);
1620 release_region (dev->base_addr, DEPCA_TOTAL_SIZE);
1621 bus = lp->depca_bus;
1622 free_netdev (dev);
1623
1624 return 0;
1625}
1626
1627
1628
1629
1630
1631
1632static int __init DepcaSignature(char *name, u_long base_addr)
1633{
1634 u_int i, j, k;
1635 void __iomem *ptr;
1636 char tmpstr[16];
1637 u_long prom_addr = base_addr + 0xc000;
1638 u_long mem_addr = base_addr + 0x8000;
1639
1640
1641
1642
1643
1644
1645 if (!request_mem_region (mem_addr, 16, depca_string))
1646 return unknown;
1647
1648
1649
1650 ptr = ioremap(prom_addr, 16);
1651 if (ptr == NULL) {
1652 printk(KERN_ERR "depca: I/O remap failed at %lx\n", prom_addr);
1653 return unknown;
1654 }
1655 for (i = 0; i < 16; i++) {
1656 tmpstr[i] = readb(ptr + i);
1657 }
1658 iounmap(ptr);
1659
1660 release_mem_region (mem_addr, 16);
1661
1662
1663 for (i = 0; *depca_signature[i] != '\0'; i++) {
1664 for (j = 0, k = 0; j < 16 && k < strlen(depca_signature[i]); j++) {
1665 if (depca_signature[i][k] == tmpstr[j]) {
1666 k++;
1667 } else {
1668 k = 0;
1669 }
1670 }
1671 if (k == strlen(depca_signature[i]))
1672 break;
1673 }
1674
1675
1676 if (name && *name && (i == unknown)) {
1677 for (i = 0; *depca_signature[i] != '\0'; i++) {
1678 if (strcmp(name, depca_signature[i]) == 0)
1679 break;
1680 }
1681 }
1682
1683 return i;
1684}
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701static int __init DevicePresent(u_long ioaddr)
1702{
1703 union {
1704 struct {
1705 u32 a;
1706 u32 b;
1707 } llsig;
1708 char Sig[sizeof(u32) << 1];
1709 }
1710 dev;
1711 short sigLength = 0;
1712 s8 data;
1713 s16 nicsr;
1714 int i, j, status = 0;
1715
1716 data = inb(DEPCA_PROM);
1717 data = inb(DEPCA_PROM);
1718
1719 if (data == 0x08) {
1720 nicsr = inb(DEPCA_NICSR);
1721 nicsr |= AAC;
1722 outb(nicsr, DEPCA_NICSR);
1723 }
1724
1725 dev.llsig.a = ETH_PROM_SIG;
1726 dev.llsig.b = ETH_PROM_SIG;
1727 sigLength = sizeof(u32) << 1;
1728
1729 for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
1730 data = inb(DEPCA_PROM);
1731 if (dev.Sig[j] == data) {
1732 j++;
1733 } else {
1734 if (data == dev.Sig[0]) {
1735 j = 1;
1736 } else {
1737 j = 0;
1738 }
1739 }
1740 }
1741
1742 if (j != sigLength) {
1743 status = -ENODEV;
1744 }
1745
1746 return status;
1747}
1748
1749
1750
1751
1752
1753
1754static int __init get_hw_addr(struct net_device *dev)
1755{
1756 u_long ioaddr = dev->base_addr;
1757 struct depca_private *lp = netdev_priv(dev);
1758 int i, k, tmp, status = 0;
1759 u_short j, x, chksum;
1760
1761 x = (((lp->adapter == de100) || (lp->adapter == de101)) ? 1 : 0);
1762
1763 for (i = 0, k = 0, j = 0; j < 3; j++) {
1764 k <<= 1;
1765 if (k > 0xffff)
1766 k -= 0xffff;
1767
1768 k += (u_char) (tmp = inb(DEPCA_PROM + x));
1769 dev->dev_addr[i++] = (u_char) tmp;
1770 k += (u_short) ((tmp = inb(DEPCA_PROM + x)) << 8);
1771 dev->dev_addr[i++] = (u_char) tmp;
1772
1773 if (k > 0xffff)
1774 k -= 0xffff;
1775 }
1776 if (k == 0xffff)
1777 k = 0;
1778
1779 chksum = (u_char) inb(DEPCA_PROM + x);
1780 chksum |= (u_short) (inb(DEPCA_PROM + x) << 8);
1781 if (k != chksum)
1782 status = -1;
1783
1784 return status;
1785}
1786
1787
1788
1789
1790static int load_packet(struct net_device *dev, struct sk_buff *skb)
1791{
1792 struct depca_private *lp = netdev_priv(dev);
1793 int i, entry, end, len, status = NETDEV_TX_OK;
1794
1795 entry = lp->tx_new;
1796 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
1797 if (!(readl(&lp->tx_ring[end].base) & T_OWN)) {
1798
1799
1800
1801
1802 if (end < entry) {
1803 len = (lp->txRingMask - entry + 1) * TX_BUFF_SZ;
1804 memcpy_toio(lp->tx_buff[entry], skb->data, len);
1805 memcpy_toio(lp->tx_buff[0], skb->data + len, skb->len - len);
1806 } else {
1807 memcpy_toio(lp->tx_buff[entry], skb->data, skb->len);
1808 }
1809
1810
1811 len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
1812 for (i = entry; i != end; i = (i+1) & lp->txRingMask) {
1813
1814 writel(readl(&lp->tx_ring[i].base) & ~T_FLAGS, &lp->tx_ring[i].base);
1815 writew(0x0000, &lp->tx_ring[i].misc);
1816 writew(-TX_BUFF_SZ, &lp->tx_ring[i].length);
1817 len -= TX_BUFF_SZ;
1818 }
1819
1820 writel(readl(&lp->tx_ring[end].base) & ~T_FLAGS, &lp->tx_ring[end].base);
1821 writew(0x0000, &lp->tx_ring[end].misc);
1822 writew(-len, &lp->tx_ring[end].length);
1823
1824
1825 writel(readl(&lp->tx_ring[entry].base) | T_STP, &lp->tx_ring[entry].base);
1826
1827 writel(readl(&lp->tx_ring[end].base) | T_ENP, &lp->tx_ring[end].base);
1828
1829 for (i = end; i != entry; --i) {
1830
1831 writel(readl(&lp->tx_ring[i].base) | T_OWN, &lp->tx_ring[i].base);
1832 if (i == 0)
1833 i = lp->txRingMask + 1;
1834 }
1835 writel(readl(&lp->tx_ring[entry].base) | T_OWN, &lp->tx_ring[entry].base);
1836
1837 lp->tx_new = (++end) & lp->txRingMask;
1838 } else {
1839 status = NETDEV_TX_LOCKED;
1840 }
1841
1842 return status;
1843}
1844
1845static void depca_dbg_open(struct net_device *dev)
1846{
1847 struct depca_private *lp = netdev_priv(dev);
1848 u_long ioaddr = dev->base_addr;
1849 struct depca_init *p = &lp->init_block;
1850 int i;
1851
1852 if (depca_debug > 1) {
1853
1854
1855
1856 printk("%s: depca open with irq %d\n", dev->name, dev->irq);
1857 printk("Descriptor head addresses (CPU):\n");
1858 printk(" 0x%lx 0x%lx\n", (u_long) lp->rx_ring, (u_long) lp->tx_ring);
1859 printk("Descriptor addresses (CPU):\nRX: ");
1860 for (i = 0; i < lp->rxRingMask; i++) {
1861 if (i < 3) {
1862 printk("%p ", &lp->rx_ring[i].base);
1863 }
1864 }
1865 printk("...%p\n", &lp->rx_ring[i].base);
1866 printk("TX: ");
1867 for (i = 0; i < lp->txRingMask; i++) {
1868 if (i < 3) {
1869 printk("%p ", &lp->tx_ring[i].base);
1870 }
1871 }
1872 printk("...%p\n", &lp->tx_ring[i].base);
1873 printk("\nDescriptor buffers (Device):\nRX: ");
1874 for (i = 0; i < lp->rxRingMask; i++) {
1875 if (i < 3) {
1876 printk("0x%8.8x ", readl(&lp->rx_ring[i].base));
1877 }
1878 }
1879 printk("...0x%8.8x\n", readl(&lp->rx_ring[i].base));
1880 printk("TX: ");
1881 for (i = 0; i < lp->txRingMask; i++) {
1882 if (i < 3) {
1883 printk("0x%8.8x ", readl(&lp->tx_ring[i].base));
1884 }
1885 }
1886 printk("...0x%8.8x\n", readl(&lp->tx_ring[i].base));
1887 printk("Initialisation block at 0x%8.8lx(Phys)\n", lp->mem_start);
1888 printk(" mode: 0x%4.4x\n", p->mode);
1889 printk(" physical address: %pM\n", p->phys_addr);
1890 printk(" multicast hash table: ");
1891 for (i = 0; i < (HASH_TABLE_LEN >> 3) - 1; i++) {
1892 printk("%2.2x:", p->mcast_table[i]);
1893 }
1894 printk("%2.2x\n", p->mcast_table[i]);
1895 printk(" rx_ring at: 0x%8.8x\n", p->rx_ring);
1896 printk(" tx_ring at: 0x%8.8x\n", p->tx_ring);
1897 printk("buffers (Phys): 0x%8.8lx\n", lp->mem_start + lp->buffs_offset);
1898 printk("Ring size:\nRX: %d Log2(rxRingMask): 0x%8.8x\n", (int) lp->rxRingMask + 1, lp->rx_rlen);
1899 printk("TX: %d Log2(txRingMask): 0x%8.8x\n", (int) lp->txRingMask + 1, lp->tx_rlen);
1900 outw(CSR2, DEPCA_ADDR);
1901 printk("CSR2&1: 0x%4.4x", inw(DEPCA_DATA));
1902 outw(CSR1, DEPCA_ADDR);
1903 printk("%4.4x\n", inw(DEPCA_DATA));
1904 outw(CSR3, DEPCA_ADDR);
1905 printk("CSR3: 0x%4.4x\n", inw(DEPCA_DATA));
1906 }
1907}
1908
1909
1910
1911
1912
1913
1914static int depca_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1915{
1916 struct depca_private *lp = netdev_priv(dev);
1917 struct depca_ioctl *ioc = (struct depca_ioctl *) &rq->ifr_ifru;
1918 int i, status = 0;
1919 u_long ioaddr = dev->base_addr;
1920 union {
1921 u8 addr[(HASH_TABLE_LEN * ETH_ALEN)];
1922 u16 sval[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
1923 u32 lval[(HASH_TABLE_LEN * ETH_ALEN) >> 2];
1924 } tmp;
1925 unsigned long flags;
1926 void *buf;
1927
1928 switch (ioc->cmd) {
1929 case DEPCA_GET_HWADDR:
1930 for (i = 0; i < ETH_ALEN; i++) {
1931 tmp.addr[i] = dev->dev_addr[i];
1932 }
1933 ioc->len = ETH_ALEN;
1934 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
1935 return -EFAULT;
1936 break;
1937
1938 case DEPCA_SET_HWADDR:
1939 if (!capable(CAP_NET_ADMIN))
1940 return -EPERM;
1941 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN))
1942 return -EFAULT;
1943 for (i = 0; i < ETH_ALEN; i++) {
1944 dev->dev_addr[i] = tmp.addr[i];
1945 }
1946 netif_stop_queue(dev);
1947 while (lp->tx_old != lp->tx_new)
1948 cpu_relax();
1949
1950 STOP_DEPCA;
1951 depca_init_ring(dev);
1952 LoadCSRs(dev);
1953 InitRestartDepca(dev);
1954 netif_start_queue(dev);
1955 break;
1956
1957 case DEPCA_SET_PROM:
1958 if (!capable(CAP_NET_ADMIN))
1959 return -EPERM;
1960 netif_stop_queue(dev);
1961 while (lp->tx_old != lp->tx_new)
1962 cpu_relax();
1963
1964 STOP_DEPCA;
1965 depca_init_ring(dev);
1966 lp->init_block.mode |= PROM;
1967
1968 LoadCSRs(dev);
1969 InitRestartDepca(dev);
1970 netif_start_queue(dev);
1971 break;
1972
1973 case DEPCA_CLR_PROM:
1974 if (!capable(CAP_NET_ADMIN))
1975 return -EPERM;
1976 netif_stop_queue(dev);
1977 while (lp->tx_old != lp->tx_new)
1978 cpu_relax();
1979
1980 STOP_DEPCA;
1981 depca_init_ring(dev);
1982 lp->init_block.mode &= ~PROM;
1983
1984 LoadCSRs(dev);
1985 InitRestartDepca(dev);
1986 netif_start_queue(dev);
1987 break;
1988
1989 case DEPCA_SAY_BOO:
1990 if(!capable(CAP_NET_ADMIN))
1991 return -EPERM;
1992 printk("%s: Boo!\n", dev->name);
1993 break;
1994
1995 case DEPCA_GET_MCA:
1996 ioc->len = (HASH_TABLE_LEN >> 3);
1997 if (copy_to_user(ioc->data, lp->init_block.mcast_table, ioc->len))
1998 return -EFAULT;
1999 break;
2000
2001 case DEPCA_SET_MCA:
2002 if (!capable(CAP_NET_ADMIN))
2003 return -EPERM;
2004 if (ioc->len >= HASH_TABLE_LEN)
2005 return -EINVAL;
2006 if (copy_from_user(tmp.addr, ioc->data, ETH_ALEN * ioc->len))
2007 return -EFAULT;
2008 set_multicast_list(dev);
2009 break;
2010
2011 case DEPCA_CLR_MCA:
2012 if (!capable(CAP_NET_ADMIN))
2013 return -EPERM;
2014 set_multicast_list(dev);
2015 break;
2016
2017 case DEPCA_MCA_EN:
2018 if (!capable(CAP_NET_ADMIN))
2019 return -EPERM;
2020 set_multicast_list(dev);
2021 break;
2022
2023 case DEPCA_GET_STATS:
2024 ioc->len = sizeof(lp->pktStats);
2025 buf = kmalloc(ioc->len, GFP_KERNEL);
2026 if(!buf)
2027 return -ENOMEM;
2028 spin_lock_irqsave(&lp->lock, flags);
2029 memcpy(buf, &lp->pktStats, ioc->len);
2030 spin_unlock_irqrestore(&lp->lock, flags);
2031 if (copy_to_user(ioc->data, buf, ioc->len))
2032 status = -EFAULT;
2033 kfree(buf);
2034 break;
2035
2036 case DEPCA_CLR_STATS:
2037 if (!capable(CAP_NET_ADMIN))
2038 return -EPERM;
2039 spin_lock_irqsave(&lp->lock, flags);
2040 memset(&lp->pktStats, 0, sizeof(lp->pktStats));
2041 spin_unlock_irqrestore(&lp->lock, flags);
2042 break;
2043
2044 case DEPCA_GET_REG:
2045 i = 0;
2046 tmp.sval[i++] = inw(DEPCA_NICSR);
2047 outw(CSR0, DEPCA_ADDR);
2048 tmp.sval[i++] = inw(DEPCA_DATA);
2049 memcpy(&tmp.sval[i], &lp->init_block, sizeof(struct depca_init));
2050 ioc->len = i + sizeof(struct depca_init);
2051 if (copy_to_user(ioc->data, tmp.addr, ioc->len))
2052 return -EFAULT;
2053 break;
2054
2055 default:
2056 return -EOPNOTSUPP;
2057 }
2058
2059 return status;
2060}
2061
2062static int __init depca_module_init (void)
2063{
2064 int err = 0;
2065
2066#ifdef CONFIG_MCA
2067 err = mca_register_driver(&depca_mca_driver);
2068 if (err)
2069 goto err;
2070#endif
2071#ifdef CONFIG_EISA
2072 err = eisa_driver_register(&depca_eisa_driver);
2073 if (err)
2074 goto err_mca;
2075#endif
2076 err = platform_driver_register(&depca_isa_driver);
2077 if (err)
2078 goto err_eisa;
2079
2080 depca_platform_probe();
2081 return 0;
2082
2083err_eisa:
2084#ifdef CONFIG_EISA
2085 eisa_driver_unregister(&depca_eisa_driver);
2086err_mca:
2087#endif
2088#ifdef CONFIG_MCA
2089 mca_unregister_driver(&depca_mca_driver);
2090err:
2091#endif
2092 return err;
2093}
2094
2095static void __exit depca_module_exit (void)
2096{
2097 int i;
2098#ifdef CONFIG_MCA
2099 mca_unregister_driver (&depca_mca_driver);
2100#endif
2101#ifdef CONFIG_EISA
2102 eisa_driver_unregister (&depca_eisa_driver);
2103#endif
2104 platform_driver_unregister (&depca_isa_driver);
2105
2106 for (i = 0; depca_io_ports[i].iobase; i++) {
2107 if (depca_io_ports[i].device) {
2108 depca_io_ports[i].device->dev.platform_data = NULL;
2109 platform_device_unregister (depca_io_ports[i].device);
2110 depca_io_ports[i].device = NULL;
2111 }
2112 }
2113}
2114
2115module_init (depca_module_init);
2116module_exit (depca_module_exit);
2117