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
145static char *version =
146 "eth16i.c: v0.35 01-Jul-1999 Mika Kuoppala (miku@iki.fi)\n";
147
148#include <linux/module.h>
149#include <linux/kernel.h>
150#include <linux/types.h>
151#include <linux/fcntl.h>
152#include <linux/interrupt.h>
153#include <linux/ioport.h>
154#include <linux/in.h>
155#include <linux/slab.h>
156#include <linux/string.h>
157#include <linux/errno.h>
158#include <linux/init.h>
159#include <linux/spinlock.h>
160#include <linux/netdevice.h>
161#include <linux/etherdevice.h>
162#include <linux/skbuff.h>
163
164#include <asm/system.h>
165#include <asm/bitops.h>
166#include <asm/io.h>
167#include <asm/dma.h>
168
169
170
171
172#define BIT(a) ( (1 << (a)) )
173#define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr)))
174#define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr)))
175
176
177#define ETH16I_IO_EXTENT 32
178
179
180#define TX_TIMEOUT (400*HZ/1000)
181
182
183#define MAX_RX_LOOP 20
184
185
186#define ETH16I_INTR_ON 0xef8a
187#define ETH16I_INTR_OFF 0x0000
188
189
190#define PKT_GOOD BIT(5)
191#define PKT_GOOD_RMT BIT(4)
192#define PKT_SHORT BIT(3)
193#define PKT_ALIGN_ERR BIT(2)
194#define PKT_CRC_ERR BIT(1)
195#define PKT_RX_BUF_OVERFLOW BIT(0)
196
197
198#define TX_STATUS_REG 0
199#define TX_DONE BIT(7)
200#define NET_BUSY BIT(6)
201#define TX_PKT_RCD BIT(5)
202#define CR_LOST BIT(4)
203#define TX_JABBER_ERR BIT(3)
204#define COLLISION BIT(2)
205#define COLLISIONS_16 BIT(1)
206
207
208#define RX_STATUS_REG 1
209#define RX_PKT BIT(7)
210#define BUS_RD_ERR BIT(6)
211#define SHORT_PKT_ERR BIT(3)
212#define ALIGN_ERR BIT(2)
213#define CRC_ERR BIT(1)
214#define RX_BUF_OVERFLOW BIT(0)
215
216
217#define TX_INTR_REG 2
218#define TX_INTR_DONE BIT(7)
219#define TX_INTR_COL BIT(2)
220#define TX_INTR_16_COL BIT(1)
221
222
223#define RX_INTR_REG 3
224#define RX_INTR_RECEIVE BIT(7)
225#define RX_INTR_SHORT_PKT BIT(3)
226#define RX_INTR_CRC_ERR BIT(1)
227#define RX_INTR_BUF_OVERFLOW BIT(0)
228
229
230#define TRANSMIT_MODE_REG 4
231#define LOOPBACK_CONTROL BIT(1)
232#define CONTROL_OUTPUT BIT(2)
233
234
235#define RECEIVE_MODE_REG 5
236#define RX_BUFFER_EMPTY BIT(6)
237#define ACCEPT_BAD_PACKETS BIT(5)
238#define RECEIVE_SHORT_ADDR BIT(4)
239#define ACCEPT_SHORT_PACKETS BIT(3)
240#define REMOTE_RESET BIT(2)
241
242#define ADDRESS_FILTER_MODE BIT(1) | BIT(0)
243#define REJECT_ALL 0
244#define ACCEPT_ALL 3
245#define MODE_1 1
246#define MODE_2 2
247
248
249#define CONFIG_REG_0 6
250#define DLC_EN BIT(7)
251#define SRAM_CYCLE_TIME_100NS BIT(6)
252#define SYSTEM_BUS_WIDTH_8 BIT(5)
253#define BUFFER_WIDTH_8 BIT(4)
254#define TBS1 BIT(3)
255#define TBS0 BIT(2)
256#define SRAM_BS1 BIT(1)
257#define SRAM_BS0 BIT(0)
258
259#ifndef ETH16I_TX_BUF_SIZE
260#define ETH16I_TX_BUF_SIZE 3
261#endif
262#define TX_BUF_1x2048 0
263#define TX_BUF_2x2048 1
264#define TX_BUF_2x4098 2
265#define TX_BUF_2x8192 3
266
267
268#define CONFIG_REG_1 7
269#define POWERUP BIT(5)
270
271
272#define TRANSMIT_START_REG 10
273#define TRANSMIT_START_RB 2
274#define TX_START BIT(7)
275
276
277#define NODE_ID_0 8
278#define NODE_ID_RB 0
279
280
281#define HASH_TABLE_0 8
282#define HASH_TABLE_RB 1
283
284
285#define BUFFER_MEM_PORT_LB 8
286#define DATAPORT BUFFER_MEM_PORT_LB
287#define BUFFER_MEM_PORT_HB 9
288
289
290#define COL_16_REG 11
291#define HALT_ON_16 0x00
292#define RETRANS_AND_HALT_ON_16 0x02
293
294
295#define MAX_COL_16 10
296
297
298#define TRANSCEIVER_MODE_REG 13
299#define TRANSCEIVER_MODE_RB 2
300#define IO_BASE_UNLOCK BIT(7)
301#define LOWER_SQUELCH_TRESH BIT(6)
302#define LINK_TEST_DISABLE BIT(5)
303#define AUI_SELECT BIT(4)
304#define DIS_AUTO_PORT_SEL BIT(3)
305
306
307#define FILTER_SELF_RX_REG 14
308#define SKIP_RX_PACKET BIT(2)
309#define FILTER_SELF_RECEIVE BIT(0)
310
311
312#define EEPROM_CTRL_REG 16
313
314
315#define EEPROM_DATA_REG 17
316
317
318#define CS_0 0x00
319#define CS_1 0x20
320#define SK_0 0x00
321#define SK_1 0x40
322#define DI_0 0x00
323#define DI_1 0x80
324
325
326#define EEPROM_READ 0x80
327
328
329#define E_NODEID_0 0x02
330#define E_NODEID_1 0x03
331#define E_NODEID_2 0x04
332#define E_PORT_SELECT 0x14
333 #define E_PORT_BNC 0x00
334 #define E_PORT_DIX 0x01
335 #define E_PORT_TP 0x02
336 #define E_PORT_AUTO 0x03
337 #define E_PORT_FROM_EPROM 0x04
338#define E_PRODUCT_CFG 0x30
339
340
341
342#define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { inb(0x80); }}while(0)
343
344
345#define JUMPERLESS_CONFIG 19
346
347
348#define ID_ROM_0 24
349#define ID_ROM_7 31
350#define RESET ID_ROM_0
351
352
353static unsigned int eth16i_portlist[] __initdata = {
354 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0
355};
356
357static unsigned int eth32i_portlist[] __initdata = {
358 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000,
359 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0
360};
361
362
363static unsigned int eth16i_irqmap[] __initdata = { 9, 10, 5, 15, 0 };
364#define NUM_OF_ISA_IRQS 4
365
366
367static unsigned int eth32i_irqmap[] __initdata = { 3, 5, 7, 9, 10, 11, 12, 15, 0 };
368#define EISA_IRQ_REG 0xc89
369#define NUM_OF_EISA_IRQS 8
370
371static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 };
372static unsigned int boot = 1;
373
374
375#ifndef ETH16I_DEBUG
376#define ETH16I_DEBUG 0
377#endif
378static unsigned int eth16i_debug = ETH16I_DEBUG;
379
380
381
382struct eth16i_local {
383 struct net_device_stats stats;
384 unsigned char tx_started;
385 unsigned char tx_buf_busy;
386 unsigned short tx_queue;
387 unsigned short tx_queue_len;
388 unsigned int tx_buf_size;
389 unsigned long open_time;
390 unsigned long tx_buffered_packets;
391 unsigned long tx_buffered_bytes;
392 unsigned long col_16;
393 spinlock_t lock;
394};
395
396
397
398extern int eth16i_probe(struct net_device *dev);
399
400static int eth16i_probe1(struct net_device *dev, int ioaddr);
401static int eth16i_check_signature(int ioaddr);
402static int eth16i_probe_port(int ioaddr);
403static void eth16i_set_port(int ioaddr, int porttype);
404static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l);
405static int eth16i_receive_probe_packet(int ioaddr);
406static int eth16i_get_irq(int ioaddr);
407static int eth16i_read_eeprom(int ioaddr, int offset);
408static int eth16i_read_eeprom_word(int ioaddr);
409static void eth16i_eeprom_cmd(int ioaddr, unsigned char command);
410static int eth16i_open(struct net_device *dev);
411static int eth16i_close(struct net_device *dev);
412static int eth16i_tx(struct sk_buff *skb, struct net_device *dev);
413static void eth16i_rx(struct net_device *dev);
414static void eth16i_timeout(struct net_device *dev);
415static irqreturn_t eth16i_interrupt(int irq, void *dev_id, struct pt_regs *regs);
416static void eth16i_reset(struct net_device *dev);
417static void eth16i_timeout(struct net_device *dev);
418static void eth16i_skip_packet(struct net_device *dev);
419static void eth16i_multicast(struct net_device *dev);
420static void eth16i_select_regbank(unsigned char regbank, int ioaddr);
421static void eth16i_initialize(struct net_device *dev);
422
423#if 0
424static int eth16i_set_irq(struct net_device *dev);
425#endif
426
427#ifdef MODULE
428static ushort eth16i_parse_mediatype(const char* s);
429#endif
430
431static struct net_device_stats *eth16i_get_stats(struct net_device *dev);
432
433static char cardname[] __initdata = "ICL EtherTeam 16i/32";
434
435int __init eth16i_probe(struct net_device *dev)
436{
437 int i;
438 int ioaddr;
439 int base_addr = dev->base_addr;
440
441 SET_MODULE_OWNER(dev);
442
443 if(eth16i_debug > 4)
444 printk(KERN_DEBUG "Probing started for %s\n", cardname);
445
446 if(base_addr > 0x1ff)
447 return eth16i_probe1(dev, base_addr);
448 else if(base_addr != 0)
449 return -ENXIO;
450
451
452 for(i = 0; (ioaddr = eth16i_portlist[i]) ; i++)
453 if(eth16i_probe1(dev, ioaddr) == 0)
454 return 0;
455
456
457 for(i = 0; (ioaddr = eth32i_portlist[i]) ; i++)
458 if(eth16i_probe1(dev, ioaddr) == 0)
459 return 0;
460
461 return -ENODEV;
462}
463
464static int __init eth16i_probe1(struct net_device *dev, int ioaddr)
465{
466 struct eth16i_local *lp;
467 static unsigned version_printed;
468 int retval;
469
470 boot = 1;
471
472
473 if (!request_region(ioaddr, ETH16I_IO_EXTENT, dev->name))
474 return -EBUSY;
475
476
477
478
479
480
481
482
483 if(ioaddr < 0x1000) {
484 if(eth16i_portlist[(inb(ioaddr + JUMPERLESS_CONFIG) & 0x07)]
485 != ioaddr) {
486 retval = -ENODEV;
487 goto out;
488 }
489 }
490
491
492
493 if(eth16i_check_signature(ioaddr) != 0) {
494 retval = -ENODEV;
495 goto out;
496 }
497
498
499
500
501
502
503
504
505
506 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
507 outb(0x00, ioaddr + TRANSCEIVER_MODE_REG);
508
509 outb(0x00, ioaddr + RESET);
510 BITSET(ioaddr + CONFIG_REG_0, BIT(7));
511
512 if( (eth16i_debug & version_printed++) == 0)
513 printk(KERN_INFO "%s", version);
514
515 dev->base_addr = ioaddr;
516 dev->irq = eth16i_get_irq(ioaddr);
517
518
519
520 if ((retval = request_irq(dev->irq, (void *)ð16i_interrupt, 0, dev->name, dev))) {
521 printk(KERN_WARNING "%s: %s at %#3x, but is unusable due conflicting IRQ %d.\n",
522 dev->name, cardname, ioaddr, dev->irq);
523 goto out;
524 }
525
526 printk(KERN_INFO "%s: %s at %#3x, IRQ %d, ",
527 dev->name, cardname, ioaddr, dev->irq);
528
529
530
531 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
532 outb(0x38, ioaddr + TRANSCEIVER_MODE_REG);
533
534 eth16i_initialize(dev);
535
536
537 BITCLR(ioaddr + CONFIG_REG_1, POWERUP);
538
539
540 if(dev->priv == NULL) {
541 dev->priv = kmalloc(sizeof(struct eth16i_local), GFP_KERNEL);
542 if(dev->priv == NULL) {
543 free_irq(dev->irq, dev);
544 retval = -ENOMEM;
545 goto out;
546 }
547 }
548
549 memset(dev->priv, 0, sizeof(struct eth16i_local));
550 dev->open = eth16i_open;
551 dev->stop = eth16i_close;
552 dev->hard_start_xmit = eth16i_tx;
553 dev->get_stats = eth16i_get_stats;
554 dev->set_multicast_list = eth16i_multicast;
555 dev->tx_timeout = eth16i_timeout;
556 dev->watchdog_timeo = TX_TIMEOUT;
557
558 lp = (struct eth16i_local *)dev->priv;
559 spin_lock_init(&lp->lock);
560
561
562 ether_setup(dev);
563
564 boot = 0;
565
566 return 0;
567out:
568 release_region(ioaddr, ETH16I_IO_EXTENT);
569 return retval;
570}
571
572
573static void eth16i_initialize(struct net_device *dev)
574{
575 int ioaddr = dev->base_addr;
576 int i, node_w = 0;
577 unsigned char node_byte = 0;
578
579
580 eth16i_select_regbank(NODE_ID_RB, ioaddr);
581 for(i = 0 ; i < 3 ; i++) {
582 unsigned short node_val = eth16i_read_eeprom(ioaddr, E_NODEID_0 + i);
583 ((unsigned short *)dev->dev_addr)[i] = ntohs(node_val);
584 }
585
586 for(i = 0; i < 6; i++) {
587 outb( ((unsigned char *)dev->dev_addr)[i], ioaddr + NODE_ID_0 + i);
588 if(boot) {
589 printk("%02x", inb(ioaddr + NODE_ID_0 + i));
590 if(i != 5)
591 printk(":");
592 }
593 }
594
595
596 eth16i_select_regbank(HASH_TABLE_RB, ioaddr);
597 for(i = 0; i < 8; i++)
598 outb(0x00, ioaddr + HASH_TABLE_0 + i);
599
600
601
602
603
604
605
606 eth16i_select_regbank(2, ioaddr);
607
608 node_byte = 0;
609 node_w = eth16i_read_eeprom(ioaddr, E_PRODUCT_CFG);
610
611 if( (node_w & 0xFF00) == 0x0800)
612 node_byte |= BUFFER_WIDTH_8;
613
614 node_byte |= SRAM_BS1;
615
616 if( (node_w & 0x00FF) == 64)
617 node_byte |= SRAM_BS0;
618
619 node_byte |= DLC_EN | SRAM_CYCLE_TIME_100NS | (ETH16I_TX_BUF_SIZE << 2);
620
621 outb(node_byte, ioaddr + CONFIG_REG_0);
622
623
624 outb(HALT_ON_16, ioaddr + COL_16_REG);
625
626#ifdef MODULE
627
628#else
629 dev->if_port = (dev->mem_start < E_PORT_FROM_EPROM) ?
630 dev->mem_start : E_PORT_FROM_EPROM;
631#endif
632
633
634 if(boot) {
635 char *porttype[] = {"BNC", "DIX", "TP", "AUTO", "FROM_EPROM" };
636
637 switch(dev->if_port)
638 {
639
640 case E_PORT_FROM_EPROM:
641 dev->if_port = eth16i_read_eeprom(ioaddr, E_PORT_SELECT);
642 break;
643
644 case E_PORT_AUTO:
645 dev->if_port = eth16i_probe_port(ioaddr);
646 break;
647
648 case E_PORT_BNC:
649 case E_PORT_TP:
650 case E_PORT_DIX:
651 break;
652 }
653
654 printk(" %s interface.\n", porttype[dev->if_port]);
655
656 eth16i_set_port(ioaddr, dev->if_port);
657 }
658
659
660 outb(MODE_2, ioaddr + RECEIVE_MODE_REG);
661}
662
663static int eth16i_probe_port(int ioaddr)
664{
665 int i;
666 int retcode;
667 unsigned char dummy_packet[64];
668
669
670 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
671
672 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
673
674 eth16i_select_regbank(NODE_ID_RB, ioaddr);
675
676 for(i = 0; i < 6; i++) {
677 dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i);
678 dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i);
679 }
680
681 dummy_packet[12] = 0x00;
682 dummy_packet[13] = 0x04;
683 memset(dummy_packet + 14, 0, sizeof(dummy_packet) - 14);
684
685 eth16i_select_regbank(2, ioaddr);
686
687 for(i = 0; i < 3; i++) {
688 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
689 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
690 eth16i_set_port(ioaddr, i);
691
692 if(eth16i_debug > 1)
693 printk(KERN_DEBUG "Set port number %d\n", i);
694
695 retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
696 if(retcode == 0) {
697 retcode = eth16i_receive_probe_packet(ioaddr);
698 if(retcode != -1) {
699 if(eth16i_debug > 1)
700 printk(KERN_DEBUG "Eth16i interface port found at %d\n", i);
701 return i;
702 }
703 }
704 else {
705 if(eth16i_debug > 1)
706 printk(KERN_DEBUG "TRANSMIT_DONE timeout when probing interface port\n");
707 }
708 }
709
710 if( eth16i_debug > 1)
711 printk(KERN_DEBUG "Using default port\n");
712
713 return E_PORT_BNC;
714}
715
716static void eth16i_set_port(int ioaddr, int porttype)
717{
718 unsigned short temp = 0;
719
720 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
721 outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG);
722
723 temp |= DIS_AUTO_PORT_SEL;
724
725 switch(porttype) {
726
727 case E_PORT_BNC :
728 temp |= AUI_SELECT;
729 break;
730
731 case E_PORT_TP :
732 break;
733
734 case E_PORT_DIX :
735 temp |= AUI_SELECT;
736 BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT);
737 break;
738 }
739
740 outb(temp, ioaddr + TRANSCEIVER_MODE_REG);
741
742 if(eth16i_debug > 1) {
743 printk(KERN_DEBUG "TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG));
744 printk(KERN_DEBUG "TRANSCEIVER_MODE_REG = %x\n",
745 inb(ioaddr+TRANSCEIVER_MODE_REG));
746 }
747}
748
749static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l)
750{
751 int starttime;
752
753 outb(0xff, ioaddr + TX_STATUS_REG);
754
755 outw(l, ioaddr + DATAPORT);
756 outsw(ioaddr + DATAPORT, (unsigned short *)b, (l + 1) >> 1);
757
758 starttime = jiffies;
759 outb(TX_START | 1, ioaddr + TRANSMIT_START_REG);
760
761 while( (inb(ioaddr + TX_STATUS_REG) & 0x80) == 0) {
762 if( (jiffies - starttime) > TX_TIMEOUT) {
763 return -1;
764 }
765 }
766
767 return 0;
768}
769
770static int eth16i_receive_probe_packet(int ioaddr)
771{
772 int starttime;
773
774 starttime = jiffies;
775
776 while((inb(ioaddr + TX_STATUS_REG) & 0x20) == 0) {
777 if( (jiffies - starttime) > TX_TIMEOUT) {
778
779 if(eth16i_debug > 1)
780 printk(KERN_DEBUG "Timeout occurred waiting transmit packet received\n");
781 starttime = jiffies;
782 while((inb(ioaddr + RX_STATUS_REG) & 0x80) == 0) {
783 if( (jiffies - starttime) > TX_TIMEOUT) {
784 if(eth16i_debug > 1)
785 printk(KERN_DEBUG "Timeout occurred waiting receive packet\n");
786 return -1;
787 }
788 }
789
790 if(eth16i_debug > 1)
791 printk(KERN_DEBUG "RECEIVE_PACKET\n");
792 return(0);
793 }
794 }
795
796 if(eth16i_debug > 1) {
797 printk(KERN_DEBUG "TRANSMIT_PACKET_RECEIVED %x\n", inb(ioaddr + TX_STATUS_REG));
798 printk(KERN_DEBUG "RX_STATUS_REG = %x\n", inb(ioaddr + RX_STATUS_REG));
799 }
800
801 return(0);
802}
803
804#if 0
805static int eth16i_set_irq(struct net_device* dev)
806{
807 const int ioaddr = dev->base_addr;
808 const int irq = dev->irq;
809 int i = 0;
810
811 if(ioaddr < 0x1000) {
812 while(eth16i_irqmap[i] && eth16i_irqmap[i] != irq)
813 i++;
814
815 if(i < NUM_OF_ISA_IRQS) {
816 u8 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
817 cbyte = (cbyte & 0x3F) | (i << 6);
818 outb(cbyte, ioaddr + JUMPERLESS_CONFIG);
819 return 0;
820 }
821 }
822 else {
823 printk(KERN_NOTICE "%s: EISA Interrupt cannot be set. Use EISA Configuration utility.\n", dev->name);
824 }
825
826 return -1;
827
828}
829#endif
830
831static int __init eth16i_get_irq(int ioaddr)
832{
833 unsigned char cbyte;
834
835 if( ioaddr < 0x1000) {
836 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
837 return( eth16i_irqmap[ ((cbyte & 0xC0) >> 6) ] );
838 } else {
839 unsigned short index = 0;
840 cbyte = inb(ioaddr + EISA_IRQ_REG);
841 while( (cbyte & 0x01) == 0) {
842 cbyte = cbyte >> 1;
843 index++;
844 }
845 return( eth32i_irqmap[ index ] );
846 }
847}
848
849static int __init eth16i_check_signature(int ioaddr)
850{
851 int i;
852 unsigned char creg[4] = { 0 };
853
854 for(i = 0; i < 4 ; i++) {
855
856 creg[i] = inb(ioaddr + TRANSMIT_MODE_REG + i);
857
858 if(eth16i_debug > 1)
859 printk("eth16i: read signature byte %x at %x\n",
860 creg[i],
861 ioaddr + TRANSMIT_MODE_REG + i);
862 }
863
864 creg[0] &= 0x0F;
865 creg[2] &= 0x7F;
866
867#if 0
868
869
870
871
872
873 if( ! ((creg[0] == 0x06) && (creg[1] == 0x41)) ) {
874 if(creg[1] != 0x42)
875 return -1;
876 }
877#endif
878
879 if( !((creg[2] == 0x36) && (creg[3] == 0xE0)) ) {
880 creg[2] &= 0x40;
881 creg[3] &= 0x03;
882
883 if( !((creg[2] == 0x40) && (creg[3] == 0x00)) )
884 return -1;
885 }
886
887 if(eth16i_read_eeprom(ioaddr, E_NODEID_0) != 0)
888 return -1;
889
890 if((eth16i_read_eeprom(ioaddr, E_NODEID_1) & 0xFF00) != 0x4B00)
891 return -1;
892
893 return 0;
894}
895
896static int eth16i_read_eeprom(int ioaddr, int offset)
897{
898 int data = 0;
899
900 eth16i_eeprom_cmd(ioaddr, EEPROM_READ | offset);
901 outb(CS_1, ioaddr + EEPROM_CTRL_REG);
902 data = eth16i_read_eeprom_word(ioaddr);
903 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
904
905 return(data);
906}
907
908static int eth16i_read_eeprom_word(int ioaddr)
909{
910 int i;
911 int data = 0;
912
913 for(i = 16; i > 0; i--) {
914 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
915 eeprom_slow_io();
916 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
917 eeprom_slow_io();
918 data = (data << 1) |
919 ((inb(ioaddr + EEPROM_DATA_REG) & DI_1) ? 1 : 0);
920
921 eeprom_slow_io();
922 }
923
924 return(data);
925}
926
927static void eth16i_eeprom_cmd(int ioaddr, unsigned char command)
928{
929 int i;
930
931 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
932 outb(DI_0, ioaddr + EEPROM_DATA_REG);
933 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
934 outb(DI_1, ioaddr + EEPROM_DATA_REG);
935 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
936
937 for(i = 7; i >= 0; i--) {
938 short cmd = ( (command & (1 << i)) ? DI_1 : DI_0 );
939 outb(cmd, ioaddr + EEPROM_DATA_REG);
940 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
941 eeprom_slow_io();
942 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
943 eeprom_slow_io();
944 }
945}
946
947static int eth16i_open(struct net_device *dev)
948{
949 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
950 int ioaddr = dev->base_addr;
951
952
953 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
954
955
956 eth16i_initialize(dev);
957
958
959 lp->tx_buf_size = eth16i_tx_buf_map[ETH16I_TX_BUF_SIZE & 0x03];
960
961 if(eth16i_debug > 0)
962 printk(KERN_DEBUG "%s: transmit buffer size %d\n",
963 dev->name, lp->tx_buf_size);
964
965
966 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
967
968
969 eth16i_select_regbank(2, ioaddr);
970
971 lp->open_time = jiffies;
972 lp->tx_started = 0;
973 lp->tx_queue = 0;
974 lp->tx_queue_len = 0;
975
976
977 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
978
979 netif_start_queue(dev);
980 return 0;
981}
982
983static int eth16i_close(struct net_device *dev)
984{
985 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
986 int ioaddr = dev->base_addr;
987
988 eth16i_reset(dev);
989
990
991 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
992
993 netif_stop_queue(dev);
994
995 lp->open_time = 0;
996
997
998 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
999
1000
1001
1002
1003
1004 outb(0x00, ioaddr + CONFIG_REG_1);
1005
1006 return 0;
1007}
1008
1009static void eth16i_timeout(struct net_device *dev)
1010{
1011 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1012 int ioaddr = dev->base_addr;
1013
1014
1015
1016
1017
1018
1019 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1020 printk(KERN_WARNING "%s: transmit timed out with status %04x, %s ?\n",
1021 dev->name,
1022 inw(ioaddr + TX_STATUS_REG), (inb(ioaddr + TX_STATUS_REG) & TX_DONE) ?
1023 "IRQ conflict" : "network cable problem");
1024
1025 dev->trans_start = jiffies;
1026
1027
1028 if(eth16i_debug > 0) {
1029 printk(KERN_DEBUG "%s: timeout: %02x %02x %02x %02x %02x %02x %02x %02x.\n",
1030 dev->name, inb(ioaddr + 0),
1031 inb(ioaddr + 1), inb(ioaddr + 2),
1032 inb(ioaddr + 3), inb(ioaddr + 4),
1033 inb(ioaddr + 5),
1034 inb(ioaddr + 6), inb(ioaddr + 7));
1035
1036 printk(KERN_DEBUG "%s: transmit start reg: %02x. collision reg %02x\n",
1037 dev->name, inb(ioaddr + TRANSMIT_START_REG),
1038 inb(ioaddr + COL_16_REG));
1039 printk(KERN_DEBUG "lp->tx_queue = %d\n", lp->tx_queue);
1040 printk(KERN_DEBUG "lp->tx_queue_len = %d\n", lp->tx_queue_len);
1041 printk(KERN_DEBUG "lp->tx_started = %d\n", lp->tx_started);
1042 }
1043 lp->stats.tx_errors++;
1044 eth16i_reset(dev);
1045 dev->trans_start = jiffies;
1046 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1047 netif_wake_queue(dev);
1048}
1049
1050static int eth16i_tx(struct sk_buff *skb, struct net_device *dev)
1051{
1052 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1053 int ioaddr = dev->base_addr;
1054 int status = 0;
1055 ushort length = skb->len;
1056 unsigned char *buf;
1057 unsigned long flags;
1058
1059 if (length < ETH_ZLEN) {
1060 skb = skb_padto(skb, ETH_ZLEN);
1061 if (skb == NULL)
1062 return 0;
1063 length = ETH_ZLEN;
1064 }
1065 buf = skb->data;
1066
1067 netif_stop_queue(dev);
1068
1069
1070 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1071
1072
1073
1074
1075 spin_lock_irqsave(&lp->lock, flags);
1076
1077 if( (length + 2) > (lp->tx_buf_size - lp->tx_queue_len)) {
1078 if(eth16i_debug > 0)
1079 printk(KERN_WARNING "%s: Transmit buffer full.\n", dev->name);
1080 }
1081 else {
1082 outw(length, ioaddr + DATAPORT);
1083
1084 if( ioaddr < 0x1000 )
1085 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
1086 else {
1087 unsigned char frag = length % 4;
1088 outsl(ioaddr + DATAPORT, buf, length >> 2);
1089 if( frag != 0 ) {
1090 outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC)), 1);
1091 if( frag == 3 )
1092 outsw(ioaddr + DATAPORT,
1093 (buf + (length & 0xFFFC) + 2), 1);
1094 }
1095 }
1096 lp->tx_buffered_packets++;
1097 lp->tx_buffered_bytes = length;
1098 lp->tx_queue++;
1099 lp->tx_queue_len += length + 2;
1100 }
1101 lp->tx_buf_busy = 0;
1102
1103 if(lp->tx_started == 0) {
1104
1105 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
1106 lp->tx_queue = 0;
1107 lp->tx_queue_len = 0;
1108 dev->trans_start = jiffies;
1109 lp->tx_started = 1;
1110 netif_wake_queue(dev);
1111 }
1112 else if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
1113
1114 netif_wake_queue(dev);
1115 }
1116
1117 spin_unlock_irqrestore(&lp->lock, flags);
1118
1119 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1120
1121
1122 status = 0;
1123 dev_kfree_skb(skb);
1124 return 0;
1125}
1126
1127static void eth16i_rx(struct net_device *dev)
1128{
1129 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1130 int ioaddr = dev->base_addr;
1131 int boguscount = MAX_RX_LOOP;
1132
1133
1134 while( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) {
1135
1136
1137 ushort status = inw(ioaddr + DATAPORT);
1138
1139
1140 ushort pkt_len = inw(ioaddr + DATAPORT);
1141
1142 if(eth16i_debug > 4)
1143 printk(KERN_DEBUG "%s: Receiving packet mode %02x status %04x.\n",
1144 dev->name,
1145 inb(ioaddr + RECEIVE_MODE_REG), status);
1146
1147 if( !(status & PKT_GOOD) ) {
1148 lp->stats.rx_errors++;
1149
1150 if( (pkt_len < ETH_ZLEN) || (pkt_len > ETH_FRAME_LEN) ) {
1151 lp->stats.rx_length_errors++;
1152 eth16i_reset(dev);
1153 return;
1154 }
1155 else {
1156 eth16i_skip_packet(dev);
1157 lp->stats.rx_dropped++;
1158 }
1159 }
1160 else {
1161 struct sk_buff *skb;
1162
1163 skb = dev_alloc_skb(pkt_len + 3);
1164 if( skb == NULL ) {
1165 printk(KERN_WARNING "%s: Could'n allocate memory for packet (len %d)\n",
1166 dev->name, pkt_len);
1167 eth16i_skip_packet(dev);
1168 lp->stats.rx_dropped++;
1169 break;
1170 }
1171
1172 skb->dev = dev;
1173 skb_reserve(skb,2);
1174
1175
1176
1177
1178
1179
1180
1181 if(ioaddr < 0x1000)
1182 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
1183 (pkt_len + 1) >> 1);
1184 else {
1185 unsigned char *buf = skb_put(skb, pkt_len);
1186 unsigned char frag = pkt_len % 4;
1187
1188 insl(ioaddr + DATAPORT, buf, pkt_len >> 2);
1189
1190 if(frag != 0) {
1191 unsigned short rest[2];
1192 rest[0] = inw( ioaddr + DATAPORT );
1193 if(frag == 3)
1194 rest[1] = inw( ioaddr + DATAPORT );
1195
1196 memcpy(buf + (pkt_len & 0xfffc), (char *)rest, frag);
1197 }
1198 }
1199
1200 skb->protocol=eth_type_trans(skb, dev);
1201
1202 if( eth16i_debug > 5 ) {
1203 int i;
1204 printk(KERN_DEBUG "%s: Received packet of length %d.\n",
1205 dev->name, pkt_len);
1206 for(i = 0; i < 14; i++)
1207 printk(KERN_DEBUG " %02x", skb->data[i]);
1208 printk(KERN_DEBUG ".\n");
1209 }
1210 netif_rx(skb);
1211 dev->last_rx = jiffies;
1212 lp->stats.rx_packets++;
1213 lp->stats.rx_bytes += pkt_len;
1214
1215 }
1216
1217 if(--boguscount <= 0)
1218 break;
1219
1220 }
1221}
1222
1223static irqreturn_t eth16i_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1224{
1225 struct net_device *dev = dev_id;
1226 struct eth16i_local *lp;
1227 int ioaddr = 0, status;
1228 int handled = 0;
1229
1230 ioaddr = dev->base_addr;
1231 lp = (struct eth16i_local *)dev->priv;
1232
1233
1234 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1235
1236
1237 spin_lock(&lp->lock);
1238
1239 status = inw(ioaddr + TX_STATUS_REG);
1240 outw(status, ioaddr + TX_STATUS_REG);
1241
1242 if (status)
1243 handled = 1;
1244
1245 if(eth16i_debug > 3)
1246 printk(KERN_DEBUG "%s: Interrupt with status %04x.\n", dev->name, status);
1247
1248 if( status & 0x7f00 ) {
1249
1250 lp->stats.rx_errors++;
1251
1252 if(status & (BUS_RD_ERR << 8) )
1253 printk(KERN_WARNING "%s: Bus read error.\n",dev->name);
1254 if(status & (SHORT_PKT_ERR << 8) ) lp->stats.rx_length_errors++;
1255 if(status & (ALIGN_ERR << 8) ) lp->stats.rx_frame_errors++;
1256 if(status & (CRC_ERR << 8) ) lp->stats.rx_crc_errors++;
1257 if(status & (RX_BUF_OVERFLOW << 8) ) lp->stats.rx_over_errors++;
1258 }
1259 if( status & 0x001a) {
1260
1261 lp->stats.tx_errors++;
1262
1263 if(status & CR_LOST) lp->stats.tx_carrier_errors++;
1264 if(status & TX_JABBER_ERR) lp->stats.tx_window_errors++;
1265
1266#if 0
1267 if(status & COLLISION) {
1268 lp->stats.collisions +=
1269 ((inb(ioaddr+TRANSMIT_MODE_REG) & 0xF0) >> 4);
1270 }
1271#endif
1272 if(status & COLLISIONS_16) {
1273 if(lp->col_16 < MAX_COL_16) {
1274 lp->col_16++;
1275 lp->stats.collisions++;
1276
1277 outb(0x02, ioaddr + COL_16_REG);
1278 }
1279 else {
1280 printk(KERN_WARNING "%s: bailing out due to many consecutive 16-in-a-row collisions. Network cable problem?\n", dev->name);
1281 }
1282 }
1283 }
1284
1285 if( status & 0x00ff ) {
1286
1287 if(status & TX_DONE) {
1288 lp->stats.tx_packets = lp->tx_buffered_packets;
1289 lp->stats.tx_bytes += lp->tx_buffered_bytes;
1290 lp->col_16 = 0;
1291
1292 if(lp->tx_queue) {
1293
1294
1295 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
1296 lp->tx_queue = 0;
1297 lp->tx_queue_len = 0;
1298 lp->tx_started = 1;
1299 }
1300 else {
1301 lp->tx_started = 0;
1302 }
1303 netif_wake_queue(dev);
1304 }
1305 }
1306
1307 if( ( status & 0x8000 ) ||
1308 ( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) ) {
1309 eth16i_rx(dev);
1310 }
1311
1312
1313 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1314
1315 if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
1316
1317 netif_wake_queue(dev);
1318 }
1319
1320 spin_unlock(&lp->lock);
1321
1322 return IRQ_RETVAL(handled);
1323}
1324
1325static void eth16i_skip_packet(struct net_device *dev)
1326{
1327 int ioaddr = dev->base_addr;
1328
1329 inw(ioaddr + DATAPORT);
1330 inw(ioaddr + DATAPORT);
1331 inw(ioaddr + DATAPORT);
1332
1333 outb(SKIP_RX_PACKET, ioaddr + FILTER_SELF_RX_REG);
1334 while( inb( ioaddr + FILTER_SELF_RX_REG ) != 0);
1335}
1336
1337static void eth16i_reset(struct net_device *dev)
1338{
1339 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1340 int ioaddr = dev->base_addr;
1341
1342 if(eth16i_debug > 1)
1343 printk(KERN_DEBUG "%s: Resetting device.\n", dev->name);
1344
1345 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
1346 outw(0xffff, ioaddr + TX_STATUS_REG);
1347 eth16i_select_regbank(2, ioaddr);
1348
1349 lp->tx_started = 0;
1350 lp->tx_buf_busy = 0;
1351 lp->tx_queue = 0;
1352 lp->tx_queue_len = 0;
1353 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
1354}
1355
1356static void eth16i_multicast(struct net_device *dev)
1357{
1358 int ioaddr = dev->base_addr;
1359
1360 if(dev->mc_count || dev->flags&(IFF_ALLMULTI|IFF_PROMISC))
1361 {
1362 dev->flags|=IFF_PROMISC;
1363 outb(3, ioaddr + RECEIVE_MODE_REG);
1364 } else {
1365 outb(2, ioaddr + RECEIVE_MODE_REG);
1366 }
1367}
1368
1369static struct net_device_stats *eth16i_get_stats(struct net_device *dev)
1370{
1371 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1372 return &lp->stats;
1373}
1374
1375static void eth16i_select_regbank(unsigned char banknbr, int ioaddr)
1376{
1377 unsigned char data;
1378
1379 data = inb(ioaddr + CONFIG_REG_1);
1380 outb( ((data & 0xF3) | ( (banknbr & 0x03) << 2)), ioaddr + CONFIG_REG_1);
1381}
1382
1383#ifdef MODULE
1384
1385static ushort eth16i_parse_mediatype(const char* s)
1386{
1387 if(!s)
1388 return E_PORT_FROM_EPROM;
1389
1390 if (!strncmp(s, "bnc", 3))
1391 return E_PORT_BNC;
1392 else if (!strncmp(s, "tp", 2))
1393 return E_PORT_TP;
1394 else if (!strncmp(s, "dix", 3))
1395 return E_PORT_DIX;
1396 else if (!strncmp(s, "auto", 4))
1397 return E_PORT_AUTO;
1398 else
1399 return E_PORT_FROM_EPROM;
1400}
1401
1402#define MAX_ETH16I_CARDS 4
1403
1404static struct net_device dev_eth16i[MAX_ETH16I_CARDS];
1405static int io[MAX_ETH16I_CARDS];
1406#if 0
1407static int irq[MAX_ETH16I_CARDS];
1408#endif
1409static char* mediatype[MAX_ETH16I_CARDS];
1410static int debug = -1;
1411
1412MODULE_AUTHOR("Mika Kuoppala <miku@iki.fi>");
1413MODULE_DESCRIPTION("ICL EtherTeam 16i/32 driver");
1414MODULE_LICENSE("GPL");
1415
1416
1417MODULE_PARM(io, "1-" __MODULE_STRING(MAX_ETH16I_CARDS) "i");
1418MODULE_PARM_DESC(io, "eth16i I/O base address(es)");
1419
1420#if 0
1421MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_ETH16I_CARDS) "i");
1422MODULE_PARM_DESC(irq, "eth16i interrupt request number");
1423#endif
1424
1425MODULE_PARM(mediatype, "1-" __MODULE_STRING(MAX_ETH16I_CARDS) "s");
1426MODULE_PARM_DESC(mediatype, "eth16i media type of interface(s) (bnc,tp,dix,auto,eprom)");
1427
1428MODULE_PARM(debug, "i");
1429MODULE_PARM_DESC(debug, "eth16i debug level (0-6)");
1430
1431int init_module(void)
1432{
1433 int this_dev, found = 0;
1434
1435 for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++)
1436 {
1437 struct net_device *dev = &dev_eth16i[this_dev];
1438
1439 dev->irq = 0;
1440 dev->base_addr = io[this_dev];
1441 dev->init = eth16i_probe;
1442
1443 if(debug != -1)
1444 eth16i_debug = debug;
1445
1446 if(eth16i_debug > 1)
1447 printk(KERN_NOTICE "eth16i(%d): interface type %s\n", this_dev, mediatype[this_dev] ? mediatype[this_dev] : "none" );
1448
1449 dev->if_port = eth16i_parse_mediatype(mediatype[this_dev]);
1450
1451 if(io[this_dev] == 0)
1452 {
1453 if(this_dev != 0) break;
1454
1455 printk(KERN_NOTICE "eth16i.c: Presently autoprobing (not recommended) for a single card.\n");
1456 }
1457
1458 if(register_netdev(dev) != 0)
1459 {
1460 printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n",
1461 io[this_dev]);
1462
1463 if(found != 0) return 0;
1464 return -ENXIO;
1465 }
1466
1467 found++;
1468 }
1469 return 0;
1470}
1471
1472void cleanup_module(void)
1473{
1474 int this_dev;
1475
1476 for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++)
1477 {
1478 struct net_device* dev = &dev_eth16i[this_dev];
1479
1480 if(dev->priv != NULL)
1481 {
1482 unregister_netdev(dev);
1483 kfree(dev->priv);
1484 dev->priv = NULL;
1485
1486 free_irq(dev->irq, dev);
1487 release_region(dev->base_addr, ETH16I_IO_EXTENT);
1488
1489 }
1490 }
1491}
1492#endif
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505