This source file includes following definitions.
- eth16i_probe
- eth16i_probe1
- eth16i_initialize
- eth16i_probe_port
- eth16i_set_port
- eth16i_send_probe_packet
- eth16i_receive_probe_packet
- eth16i_get_irq
- eth16i_check_signature
- eth16i_read_eeprom
- eth16i_read_eeprom_word
- eth16i_eeprom_cmd
- eth16i_open
- eth16i_close
- eth16i_tx
- eth16i_rx
- eth16i_interrupt
- eth16i_multicast
- eth16i_get_stats
- eth16i_select_regbank
- 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 static char *version =
71 "eth16i.c: v0.21 17-10-95 Mika Kuoppala (miku@pupu.elt.icl.fi)\n";
72
73 #include <linux/module.h>
74
75 #include <linux/kernel.h>
76 #include <linux/sched.h>
77 #include <linux/types.h>
78 #include <linux/fcntl.h>
79 #include <linux/interrupt.h>
80 #include <linux/ptrace.h>
81 #include <linux/ioport.h>
82 #include <linux/in.h>
83 #include <linux/malloc.h>
84 #include <linux/string.h>
85 #include <linux/errno.h>
86
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
90
91 #include <asm/system.h>
92 #include <asm/bitops.h>
93 #include <asm/io.h>
94 #include <asm/dma.h>
95
96
97 #define BIT(a) ( (1 << (a)) )
98 #define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr)))
99 #define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr)))
100
101
102 #define ETH16I_IO_EXTENT 32
103
104
105 #define TIMEOUT_TICKS 30
106
107
108 #define MAX_RX_LOOP 40
109
110
111 #define ETH16I_INTR_ON 0x8f82
112 #define ETH16I_INTR_OFF 0x0000
113
114
115 #define PKT_GOOD BIT(5)
116 #define PKT_GOOD_RMT BIT(4)
117 #define PKT_SHORT BIT(3)
118 #define PKT_ALIGN_ERR BIT(2)
119 #define PKT_CRC_ERR BIT(1)
120 #define PKT_RX_BUF_OVERFLOW BIT(0)
121
122
123 #define TX_STATUS_REG 0
124 #define TX_DONE BIT(7)
125 #define NET_BUSY BIT(6)
126 #define TX_PKT_RCD BIT(5)
127 #define CR_LOST BIT(4)
128 #define COLLISION BIT(2)
129 #define COLLISIONS_16 BIT(1)
130
131
132 #define RX_STATUS_REG 1
133 #define RX_PKT BIT(7)
134 #define BUS_RD_ERR BIT(6)
135 #define SHORT_PKT_ERR BIT(3)
136 #define ALIGN_ERR BIT(2)
137 #define CRC_ERR BIT(1)
138 #define RX_BUF_OVERFLOW BIT(0)
139
140
141 #define TX_INTR_REG 2
142 #define TX_INTR_DONE BIT(7)
143 #define TX_INTR_COL BIT(2)
144 #define TX_INTR_16_COL BIT(1)
145
146
147 #define RX_INTR_REG 3
148 #define RX_INTR_RECEIVE BIT(7)
149 #define RX_INTR_SHORT_PKT BIT(3)
150 #define RX_INTR_CRC_ERR BIT(1)
151 #define RX_INTR_BUF_OVERFLOW BIT(0)
152
153
154 #define TRANSMIT_MODE_REG 4
155 #define LOOPBACK_CONTROL BIT(1)
156 #define CONTROL_OUTPUT BIT(2)
157
158
159 #define RECEIVE_MODE_REG 5
160 #define RX_BUFFER_EMPTY BIT(6)
161 #define ACCEPT_BAD_PACKETS BIT(5)
162 #define RECEIVE_SHORT_ADDR BIT(4)
163 #define ACCEPT_SHORT_PACKETS BIT(3)
164 #define REMOTE_RESET BIT(2)
165
166 #define ADDRESS_FILTER_MODE BIT(1) | BIT(0)
167 #define REJECT_ALL 0
168 #define ACCEPT_ALL 3
169 #define MODE_1 1
170 #define MODE_2 2
171
172
173 #define CONFIG_REG_0 6
174 #define DLC_EN BIT(7)
175 #define SRAM_CYCLE_TIME_100NS BIT(6)
176 #define SYSTEM_BUS_WIDTH_8 BIT(5)
177 #define BUFFER_WIDTH_8 BIT(4)
178 #define TBS1 BIT(3)
179 #define TBS0 BIT(2)
180 #define BS1 BIT(1)
181 #define BS0 BIT(0)
182
183 #ifndef ETH16I_TX_BUF_SIZE
184 #define ETH16I_TX_BUF_SIZE 2
185 #endif
186 #define TX_BUF_1x2048 0
187 #define TX_BUF_2x2048 1
188 #define TX_BUF_2x4098 2
189 #define TX_BUF_2x8192 3
190
191
192 #define CONFIG_REG_1 7
193 #define POWERUP BIT(5)
194
195
196 #define TRANSMIT_START_REG 10
197 #define TRANSMIT_START_RB 2
198 #define TX_START BIT(7)
199
200
201 #define NODE_ID_0 8
202 #define NODE_ID_RB 0
203
204
205 #define HASH_TABLE_0 8
206 #define HASH_TABLE_RB 1
207
208
209 #define BUFFER_MEM_PORT_LB 8
210 #define DATAPORT BUFFER_MEM_PORT_LB
211 #define BUFFER_MEM_PORT_HB 9
212
213
214 #define COL_16_REG 11
215 #define HALT_ON_16 0x00
216 #define RETRANS_AND_HALT_ON_16 0x02
217
218
219 #define TRANSCEIVER_MODE_REG 13
220 #define TRANSCEIVER_MODE_RB 2
221 #define IO_BASE_UNLOCK BIT(7)
222 #define LOWER_SQUELCH_TRESH BIT(6)
223 #define LINK_TEST_DISABLE BIT(5)
224 #define AUI_SELECT BIT(4)
225 #define DIS_AUTO_PORT_SEL BIT(3)
226
227
228 #define FILTER_SELF_RX_REG 14
229 #define SKIP_RECEIVE_PACKET BIT(2)
230 #define FILTER_SELF_RECEIVE BIT(0)
231 #define RX_BUF_SKIP_PACKET SKIP_RECEIVE_PACKET | FILTER_SELF_RECEIVE
232
233
234 #define EEPROM_CTRL_REG 16
235
236
237 #define EEPROM_DATA_REG 17
238
239
240 #define CS_0 0x00
241 #define CS_1 0x20
242 #define SK_0 0x00
243 #define SK_1 0x40
244 #define DI_0 0x00
245 #define DI_1 0x80
246
247
248 #define EEPROM_READ 0x80
249
250
251 #define E_NODEID_0 0x02
252 #define E_NODEID_1 0x03
253 #define E_NODEID_2 0x04
254 #define E_PORT_SELECT 0x14
255 #define E_PORT_BNC 0
256 #define E_PORT_DIX 1
257 #define E_PORT_TP 2
258 #define E_PORT_AUTO 3
259 #define E_PRODUCT_CFG 0x30
260
261
262
263 #define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { __SLOW_DOWN_IO; }}while(0)
264
265
266 #define JUMPERLESS_CONFIG 19
267
268
269 #define ID_ROM_0 24
270 #define ID_ROM_7 31
271 #define RESET ID_ROM_0
272
273
274 static unsigned int eth16i_portlist[] =
275 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0 };
276
277 static unsigned int eth32i_portlist[] =
278 { 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000,
279 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0 };
280
281
282 static unsigned int eth16i_irqmap[] = { 9, 10, 5, 15 };
283
284
285 static unsigned int eth32i_irqmap[] = { 3, 5, 7, 9, 10, 11, 12, 15 };
286 #define EISA_IRQ_REG 0xc89
287
288 static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 };
289 unsigned int boot = 1;
290
291
292 #ifndef ETH16I_DEBUG
293 #define ETH16I_DEBUG 0
294 #endif
295 static unsigned int eth16i_debug = ETH16I_DEBUG;
296
297
298 struct eth16i_local {
299 struct enet_statistics stats;
300 unsigned int tx_started:1;
301 unsigned char tx_queue;
302 unsigned short tx_queue_len;
303 unsigned int tx_buf_size;
304 unsigned long open_time;
305 };
306
307
308
309 extern int eth16i_probe(struct device *dev);
310
311 static int eth16i_probe1(struct device *dev, short ioaddr);
312 static int eth16i_check_signature(short ioaddr);
313 static int eth16i_probe_port(short ioaddr);
314 static void eth16i_set_port(short ioaddr, int porttype);
315 static int eth16i_send_probe_packet(short ioaddr, unsigned char *b, int l);
316 static int eth16i_receive_probe_packet(short ioaddr);
317 static int eth16i_get_irq(short ioaddr);
318 static int eth16i_read_eeprom(int ioaddr, int offset);
319 static int eth16i_read_eeprom_word(int ioaddr);
320 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command);
321 static int eth16i_open(struct device *dev);
322 static int eth16i_close(struct device *dev);
323 static int eth16i_tx(struct sk_buff *skb, struct device *dev);
324 static void eth16i_rx(struct device *dev);
325 static void eth16i_interrupt(int irq, struct pt_regs *regs);
326 static void eth16i_multicast(struct device *dev, int num_addrs, void *addrs);
327 static void eth16i_select_regbank(unsigned char regbank, short ioaddr);
328 static void eth16i_initialize(struct device *dev);
329 static struct enet_statistics *eth16i_get_stats(struct device *dev);
330
331 static char *cardname = "ICL EtherTeam 16i/32";
332
333 #ifdef HAVE_DEVLIST
334
335 /struct netdev_entry eth16i_drv =
336 {"eth16i", eth16i_probe1, ETH16I_IO_EXTENT, eth16i_probe_list};
337
338 #else
339 int eth16i_probe(struct device *dev)
340 {
341 int i;
342 int ioaddr;
343 int base_addr = dev ? dev->base_addr : 0;
344
345 if(eth16i_debug > 4)
346 printk("Probing started for %s\n", cardname);
347
348 if(base_addr > 0x1ff)
349 return eth16i_probe1(dev, base_addr);
350 else if(base_addr != 0)
351 return ENXIO;
352
353
354 for(i = 0; (ioaddr = eth16i_portlist[i]) ; i++) {
355 if(check_region(ioaddr, ETH16I_IO_EXTENT))
356 continue;
357 if(eth16i_probe1(dev, ioaddr) == 0)
358 return 0;
359 }
360
361
362 for(i = 0; (ioaddr = eth32i_portlist[i]) ; i++) {
363 if(check_region(ioaddr, ETH16I_IO_EXTENT))
364 continue;
365 if(eth16i_probe1(dev, ioaddr) == 0)
366 return 0;
367 }
368
369 return ENODEV;
370 }
371 #endif
372
373 static int eth16i_probe1(struct device *dev, short ioaddr)
374 {
375 static unsigned version_printed = 0;
376 unsigned int irq = 0;
377 boot = 1;
378
379
380
381
382
383
384
385
386 if(ioaddr < 0x1000) {
387 if(eth16i_portlist[(inb(ioaddr + JUMPERLESS_CONFIG) & 0x07)] != ioaddr)
388 return -ENODEV;
389 }
390
391
392
393 if(eth16i_check_signature(ioaddr) != 0)
394 return -ENODEV;
395
396
397
398
399
400
401
402
403
404 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
405 outb(0x00, ioaddr + TRANSCEIVER_MODE_REG);
406
407 outb(0x00, ioaddr + RESET);
408 BITSET(ioaddr + CONFIG_REG_0, BIT(7));
409
410 if(dev == NULL)
411 dev = init_etherdev(0, sizeof(struct eth16i_local));
412
413 if( (eth16i_debug & version_printed++) == 0)
414 printk(version);
415
416 dev->base_addr = ioaddr;
417
418 irq = eth16i_get_irq(ioaddr);
419 dev->irq = irq;
420
421
422 if(request_irq(dev->irq, ð16i_interrupt, 0, "eth16i")) {
423 printk("%s: %s at %#3x, but is unusable due
424 conflict on IRQ %d.\n", dev->name, cardname, ioaddr, irq);
425 return EAGAIN;
426 }
427
428 printk("%s: %s at %#3x, IRQ %d, ",
429 dev->name, cardname, ioaddr, dev->irq);
430
431
432 request_region(ioaddr, ETH16I_IO_EXTENT, "eth16i");
433
434
435 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
436 outb(0x38, ioaddr + TRANSCEIVER_MODE_REG);
437
438 eth16i_initialize(dev);
439
440
441 BITCLR(ioaddr + CONFIG_REG_1, POWERUP);
442
443
444 if(dev->priv == NULL)
445 dev->priv = kmalloc(sizeof(struct eth16i_local), GFP_KERNEL);
446 memset(dev->priv, 0, sizeof(struct eth16i_local));
447
448 dev->open = eth16i_open;
449 dev->stop = eth16i_close;
450 dev->hard_start_xmit = eth16i_tx;
451 dev->get_stats = eth16i_get_stats;
452 dev->set_multicast_list = ð16i_multicast;
453
454
455 ether_setup(dev);
456
457 boot = 0;
458
459 return 0;
460 }
461
462
463 static void eth16i_initialize(struct device *dev)
464 {
465 short ioaddr = dev->base_addr;
466 int i, node_w = 0;
467 unsigned char node_byte = 0;
468
469
470 eth16i_select_regbank(NODE_ID_RB, ioaddr);
471 for(i = 0 ; i < 3 ; i++) {
472 unsigned short node_val = eth16i_read_eeprom(ioaddr, E_NODEID_0 + i);
473 ((unsigned short *)dev->dev_addr)[i] = ntohs(node_val);
474 }
475
476 for(i = 0; i < 6; i++) {
477 outb( ((unsigned char *)dev->dev_addr)[i], ioaddr + NODE_ID_0 + i);
478 if(boot) {
479 printk("%02x", inb(ioaddr + NODE_ID_0 + i));
480 if(i != 5)
481 printk(":");
482 }
483 }
484
485
486 eth16i_select_regbank(HASH_TABLE_RB, ioaddr);
487 for(i = 0; i < 8; i++)
488 outb(0x00, ioaddr + HASH_TABLE_0 + i);
489
490
491
492
493
494
495
496 eth16i_select_regbank(2, ioaddr);
497
498 node_byte = 0;
499 node_w = eth16i_read_eeprom(ioaddr, E_PRODUCT_CFG);
500
501 if( (node_w & 0xFF00) == 0x0800)
502 node_byte |= BUFFER_WIDTH_8;
503
504 node_byte |= BS1;
505
506 if( (node_w & 0x00FF) == 64)
507 node_byte |= BS0;
508
509 node_byte |= DLC_EN | SRAM_CYCLE_TIME_100NS | (ETH16I_TX_BUF_SIZE << 2);
510
511 outb(node_byte, ioaddr + CONFIG_REG_0);
512
513
514 outb(RETRANS_AND_HALT_ON_16, ioaddr + COL_16_REG);
515
516 if(boot)
517 {
518 char *porttype[] = {"BNC", "DIX", "TP", "AUTO"};
519
520 ushort ptype = eth16i_read_eeprom(ioaddr, E_PORT_SELECT);
521 dev->if_port = (ptype & 0x00FF);
522
523 printk(" %s interface.\n", porttype[dev->if_port]);
524
525 if(ptype == E_PORT_AUTO)
526 ptype = eth16i_probe_port(ioaddr);
527
528 eth16i_set_port(ioaddr, ptype);
529 }
530
531
532 outb(MODE_2, ioaddr + RECEIVE_MODE_REG);
533 }
534
535 static int eth16i_probe_port(short ioaddr)
536 {
537 int i;
538 int retcode;
539 unsigned char dummy_packet[64] = { 0 };
540
541
542 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
543
544 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
545
546 eth16i_select_regbank(NODE_ID_RB, ioaddr);
547
548 for(i = 0; i < 6; i++) {
549 dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i);
550 dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i);
551 }
552
553 dummy_packet[12] = 0x00;
554 dummy_packet[13] = 0x04;
555
556 eth16i_select_regbank(2, ioaddr);
557
558 for(i = 0; i < 3; i++) {
559 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
560 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
561 eth16i_set_port(ioaddr, i);
562
563 if(eth16i_debug > 1)
564 printk("Set port number %d\n", i);
565
566 retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
567 if(retcode == 0) {
568 retcode = eth16i_receive_probe_packet(ioaddr);
569 if(retcode != -1) {
570 if(eth16i_debug > 1)
571 printk("Eth16i interface port found at %d\n", i);
572 return i;
573 }
574 }
575 else {
576 if(eth16i_debug > 1)
577 printk("TRANSMIT_DONE timeout\n");
578 }
579 }
580
581 if( eth16i_debug > 1)
582 printk("Using default port\n");
583
584 return E_PORT_BNC;
585 }
586
587 static void eth16i_set_port(short ioaddr, int porttype)
588 {
589 unsigned short temp = 0;
590
591 eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
592 outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG);
593
594 temp |= DIS_AUTO_PORT_SEL;
595
596 switch(porttype) {
597
598 case E_PORT_BNC :
599 temp |= AUI_SELECT;
600 break;
601
602 case E_PORT_TP :
603 break;
604
605 case E_PORT_DIX :
606 temp |= AUI_SELECT;
607 BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT);
608 break;
609 }
610 outb(temp, ioaddr + TRANSCEIVER_MODE_REG);
611
612 if(eth16i_debug > 1) {
613 printk("TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG));
614 printk("TRANSCEIVER_MODE_REG = %x\n", inb(ioaddr+TRANSCEIVER_MODE_REG));
615 }
616 }
617
618 static int eth16i_send_probe_packet(short ioaddr, unsigned char *b, int l)
619 {
620 int starttime;
621
622 outb(0xff, ioaddr + TX_STATUS_REG);
623
624 outw(l, ioaddr + DATAPORT);
625 outsw(ioaddr + DATAPORT, (unsigned short *)b, (l + 1) >> 1);
626
627 starttime = jiffies;
628 outb(TX_START | 1, ioaddr + TRANSMIT_START_REG);
629
630 while( (inb(ioaddr + TX_STATUS_REG) & 0x80) == 0) {
631 if( (jiffies - starttime) > TIMEOUT_TICKS) {
632 break;
633 }
634 }
635
636 return(0);
637 }
638
639 static int eth16i_receive_probe_packet(short ioaddr)
640 {
641 int starttime;
642
643 starttime = jiffies;
644
645 while((inb(ioaddr + TX_STATUS_REG) & 0x20) == 0) {
646 if( (jiffies - starttime) > TIMEOUT_TICKS) {
647
648 if(eth16i_debug > 1)
649 printk("Timeout occured waiting transmit packet received\n");
650 starttime = jiffies;
651 while((inb(ioaddr + RX_STATUS_REG) & 0x80) == 0) {
652 if( (jiffies - starttime) > TIMEOUT_TICKS) {
653 if(eth16i_debug > 1)
654 printk("Timeout occured waiting receive packet\n");
655 return -1;
656 }
657 }
658
659 if(eth16i_debug > 1)
660 printk("RECEIVE_PACKET\n");
661 return(0);
662 }
663 }
664
665 if(eth16i_debug > 1) {
666 printk("TRANSMIT_PACKET_RECEIVED %x\n", inb(ioaddr + TX_STATUS_REG));
667 printk("RX_STATUS_REG = %x\n", inb(ioaddr + RX_STATUS_REG));
668 }
669
670 return(0);
671 }
672
673 static int eth16i_get_irq(short ioaddr)
674 {
675 unsigned char cbyte;
676
677 if( ioaddr < 0x1000) {
678 cbyte = inb(ioaddr + JUMPERLESS_CONFIG);
679 return( eth16i_irqmap[ ((cbyte & 0xC0) >> 6) ] );
680 } else {
681 unsigned short index = 0;
682 cbyte = inb(ioaddr + EISA_IRQ_REG);
683 while( (cbyte & 0x01) == 0) {
684 cbyte = cbyte >> 1;
685 index++;
686 }
687 return( eth32i_irqmap[ index ] );
688 }
689 }
690
691 static int eth16i_check_signature(short ioaddr)
692 {
693 int i;
694 unsigned char creg[4] = { 0 };
695
696 for(i = 0; i < 4 ; i++) {
697
698 creg[i] = inb(ioaddr + TRANSMIT_MODE_REG + i);
699
700 if(eth16i_debug > 1)
701 printk("eth16i: read signature byte %x at %x\n", creg[i],
702 ioaddr + TRANSMIT_MODE_REG + i);
703 }
704
705 creg[0] &= 0x0F;
706 creg[2] &= 0x7F;
707
708 #ifdef 0
709
710
711
712
713
714 if( !( (creg[0] == 0x06) && (creg[1] == 0x41)) ) {
715 if(creg[1] != 0x42)
716 return -1;
717 }
718 #endif
719
720 if( !( (creg[2] == 0x36) && (creg[3] == 0xE0)) ) {
721 creg[2] &= 0x42;
722 creg[3] &= 0x03;
723
724 if( !( (creg[2] == 0x42) && (creg[3] == 0x00)) )
725 return -1;
726 }
727
728 if(eth16i_read_eeprom(ioaddr, E_NODEID_0) != 0)
729 return -1;
730 if((eth16i_read_eeprom(ioaddr, E_NODEID_1) & 0xFF00) != 0x4B00)
731 return -1;
732
733 return 0;
734 }
735
736 static int eth16i_read_eeprom(int ioaddr, int offset)
737 {
738 int data = 0;
739
740 eth16i_eeprom_cmd(ioaddr, EEPROM_READ | offset);
741 outb(CS_1, ioaddr + EEPROM_CTRL_REG);
742 data = eth16i_read_eeprom_word(ioaddr);
743 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
744
745 return(data);
746 }
747
748 static int eth16i_read_eeprom_word(int ioaddr)
749 {
750 int i;
751 int data = 0;
752
753 for(i = 16; i > 0; i--) {
754 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
755 eeprom_slow_io();
756 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
757 eeprom_slow_io();
758 data = (data << 1) | ((inb(ioaddr + EEPROM_DATA_REG) & DI_1) ? 1 : 0);
759 eeprom_slow_io();
760 }
761
762 return(data);
763 }
764
765 static void eth16i_eeprom_cmd(int ioaddr, unsigned char command)
766 {
767 int i;
768
769 outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG);
770 outb(DI_0, ioaddr + EEPROM_DATA_REG);
771 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
772 outb(DI_1, ioaddr + EEPROM_DATA_REG);
773 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
774
775 for(i = 7; i >= 0; i--) {
776 short cmd = ( (command & (1 << i)) ? DI_1 : DI_0 );
777 outb(cmd, ioaddr + EEPROM_DATA_REG);
778 outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG);
779 eeprom_slow_io();
780 outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG);
781 eeprom_slow_io();
782 }
783 }
784
785 static int eth16i_open(struct device *dev)
786 {
787 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
788 int ioaddr = dev->base_addr;
789
790 irq2dev_map[dev->irq] = dev;
791
792
793 outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);
794
795
796 eth16i_initialize(dev);
797
798
799 lp->tx_buf_size = eth16i_tx_buf_map[ETH16I_TX_BUF_SIZE & 0x03];
800
801 if(eth16i_debug > 3)
802 printk("%s: transmit buffer size %d\n", dev->name, lp->tx_buf_size);
803
804
805 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
806
807
808 eth16i_select_regbank(2, ioaddr);
809
810 lp->open_time = jiffies;
811 lp->tx_started = 0;
812 lp->tx_queue = 0;
813 lp->tx_queue_len = 0;
814
815
816 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
817
818 dev->tbusy = 0;
819 dev->interrupt = 0;
820 dev->start = 1;
821
822 #ifdef MODULE
823 MOD_INC_USE_COUNT;
824 #endif
825
826 return 0;
827 }
828
829 static int eth16i_close(struct device *dev)
830 {
831 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
832 int ioaddr = dev->base_addr;
833
834 lp->open_time = 0;
835
836 dev->tbusy = 1;
837 dev->start = 0;
838
839
840 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
841
842
843 outb(0xff, ioaddr + RESET);
844
845
846 BITCLR(ioaddr + CONFIG_REG_1, POWERUP);
847
848 #ifdef MODULE
849 MOD_DEC_USE_COUNT;
850 #endif
851
852 return 0;
853 }
854
855 static int eth16i_tx(struct sk_buff *skb, struct device *dev)
856 {
857 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
858 int ioaddr = dev->base_addr;
859
860 if(dev->tbusy) {
861
862
863
864
865
866 int tickssofar = jiffies - dev->trans_start;
867 if(tickssofar < TIMEOUT_TICKS)
868 return 1;
869
870 printk("%s: transmit timed out with status %04x, %s ?\n", dev->name,
871 inw(ioaddr + TX_STATUS_REG),
872 (inb(ioaddr + TX_STATUS_REG) & TX_DONE) ?
873 "IRQ conflict" : "network cable problem");
874
875
876 if(eth16i_debug > 0) {
877 printk("%s: timeout regs: %02x %02x %02x %02x %02x %02x %02x %02x.\n",
878 dev->name, inb(ioaddr + 0), inb(ioaddr + 1), inb(ioaddr + 2),
879 inb(ioaddr + 3), inb(ioaddr + 4), inb(ioaddr + 5),
880 inb(ioaddr + 6), inb(ioaddr + 7));
881
882
883 printk("lp->tx_queue = %d\n", lp->tx_queue);
884 printk("lp->tx_queue_len = %d\n", lp->tx_queue_len);
885 printk("lp->tx_started = %d\n", lp->tx_started);
886
887 }
888
889 lp->stats.tx_errors++;
890
891
892
893 BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
894 outw(0xffff, ioaddr + RESET);
895 eth16i_initialize(dev);
896 outw(0xffff, ioaddr + TX_STATUS_REG);
897 BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
898
899 lp->tx_started = 0;
900 lp->tx_queue = 0;
901 lp->tx_queue_len = 0;
902
903 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
904
905 dev->tbusy = 0;
906 dev->trans_start = jiffies;
907 }
908
909
910
911
912
913
914 if(skb == NULL) {
915 dev_tint(dev);
916 return 0;
917 }
918
919
920
921
922
923 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
924
925 if(set_bit(0, (void *)&dev->tbusy) != 0)
926 printk("%s: Transmitter access conflict.\n", dev->name);
927 else {
928 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
929 unsigned char *buf = skb->data;
930
931 outw(length, ioaddr + DATAPORT);
932
933 if( ioaddr < 0x1000 )
934 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
935 else {
936 unsigned char frag = length % 4;
937
938 outsl(ioaddr + DATAPORT, buf, length >> 2);
939
940 if( frag != 0 ) {
941 outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC)), 1);
942 if( frag == 3 )
943 outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC) + 2), 1);
944 }
945 }
946
947 lp->tx_queue++;
948 lp->tx_queue_len += length + 2;
949
950 if(lp->tx_started == 0) {
951
952 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
953 lp->tx_queue = 0;
954 lp->tx_queue_len = 0;
955 dev->trans_start = jiffies;
956 lp->tx_started = 1;
957 dev->tbusy = 0;
958 }
959 else if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) {
960
961 dev->tbusy = 0;
962 }
963
964 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
965
966
967
968 }
969 dev_kfree_skb(skb, FREE_WRITE);
970
971 return 0;
972 }
973
974 static void eth16i_rx(struct device *dev)
975 {
976 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
977 int ioaddr = dev->base_addr;
978 int boguscount = MAX_RX_LOOP;
979
980
981 while( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) {
982
983
984 ushort status = inw(ioaddr + DATAPORT);
985
986 if(eth16i_debug > 4)
987 printk("%s: Receiving packet mode %02x status %04x.\n",
988 dev->name, inb(ioaddr + RECEIVE_MODE_REG), status);
989
990 if( !(status & PKT_GOOD) ) {
991
992 lp->stats.rx_errors++;
993 if( status & PKT_SHORT ) lp->stats.rx_length_errors++;
994 if( status & PKT_ALIGN_ERR ) lp->stats.rx_frame_errors++;
995 if( status & PKT_CRC_ERR ) lp->stats.rx_crc_errors++;
996 if( status & PKT_RX_BUF_OVERFLOW) lp->stats.rx_over_errors++;
997 }
998 else {
999 struct sk_buff *skb;
1000
1001
1002 ushort pkt_len = inw(ioaddr + DATAPORT);
1003
1004 if(pkt_len > ETH_FRAME_LEN) {
1005 printk("%s: %s claimed a very large packet, size of %d bytes.\n",
1006 dev->name, cardname, pkt_len);
1007 outb(RX_BUF_SKIP_PACKET, ioaddr + FILTER_SELF_RX_REG);
1008 lp->stats.rx_dropped++;
1009 break;
1010 }
1011
1012 skb = dev_alloc_skb(pkt_len + 3);
1013 if( skb == NULL ) {
1014 printk("%s: Could'n allocate memory for packet (len %d)\n",
1015 dev->name, pkt_len);
1016 outb(RX_BUF_SKIP_PACKET, ioaddr + FILTER_SELF_RX_REG);
1017 lp->stats.rx_dropped++;
1018 break;
1019 }
1020
1021 skb->dev = dev;
1022 skb_reserve(skb,2);
1023
1024
1025
1026
1027
1028
1029 if( ioaddr < 0x1000)
1030 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len), (pkt_len + 1) >> 1);
1031 else {
1032 unsigned char *buf = skb_put(skb, pkt_len);
1033 unsigned char frag = pkt_len % 4;
1034
1035 insl(ioaddr + DATAPORT, buf, pkt_len >> 2);
1036
1037 if(frag != 0) {
1038 unsigned short rest[2];
1039 rest[0] = inw( ioaddr + DATAPORT );
1040 if(frag == 3)
1041 rest[1] = inw( ioaddr + DATAPORT );
1042
1043 memcpy(buf + (pkt_len & 0xfffc), (char *)rest, frag);
1044 }
1045 }
1046
1047 skb->protocol=eth_type_trans(skb, dev);
1048 netif_rx(skb);
1049 lp->stats.rx_packets++;
1050
1051 if( eth16i_debug > 5 ) {
1052 int i;
1053 printk("%s: Received packet of length %d.\n", dev->name, pkt_len);
1054 for(i = 0; i < 14; i++)
1055 printk(" %02x", skb->data[i]);
1056 printk(".\n");
1057 }
1058
1059 }
1060
1061 if(--boguscount <= 0)
1062 break;
1063
1064 }
1065
1066 #if 0
1067 {
1068 int i;
1069
1070 for(i = 0; i < 20; i++) {
1071 if( (inb(ioaddr+RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == RX_BUFFER_EMPTY)
1072 break;
1073 inw(ioaddr + DATAPORT);
1074 outb(RX_BUF_SKIP_PACKET, ioaddr + FILTER_SELF_RX_REG);
1075 }
1076
1077 if(eth16i_debug > 1)
1078 printk("%s: Flushed receive buffer.\n", dev->name);
1079 }
1080 #endif
1081
1082 return;
1083 }
1084
1085 static void eth16i_interrupt(int irq, struct pt_regs *regs)
1086 {
1087 struct device *dev = (struct device *)(irq2dev_map[irq]);
1088 struct eth16i_local *lp;
1089 int ioaddr = 0,
1090 status;
1091
1092 if(dev == NULL) {
1093 printk("eth16i_interrupt(): irq %d for unknown device. \n", irq);
1094 return;
1095 }
1096
1097
1098 outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG);
1099
1100 dev->interrupt = 1;
1101
1102 ioaddr = dev->base_addr;
1103 lp = (struct eth16i_local *)dev->priv;
1104 status = inw(ioaddr + TX_STATUS_REG);
1105 outw(status, ioaddr + TX_STATUS_REG);
1106
1107 if(eth16i_debug > 3)
1108 printk("%s: Interrupt with status %04x.\n", dev->name, status);
1109
1110 if( status & 0x00ff ) {
1111
1112 if(status & TX_DONE) {
1113 lp->stats.tx_packets++;
1114
1115 if(lp->tx_queue) {
1116
1117
1118 outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG);
1119 lp->tx_queue = 0;
1120 lp->tx_queue_len = 0;
1121 dev->trans_start = jiffies;
1122 dev->tbusy = 0;
1123 mark_bh(NET_BH);
1124 }
1125 else {
1126 lp->tx_started = 0;
1127 dev->tbusy = 0;
1128 mark_bh(NET_BH);
1129 }
1130 }
1131 }
1132
1133 if( ( status & 0xff00 ) ||
1134 ( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) ) {
1135 eth16i_rx(dev);
1136 }
1137
1138 dev->interrupt = 0;
1139
1140
1141 outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG);
1142
1143 return;
1144 }
1145
1146 static void eth16i_multicast(struct device *dev, int num_addrs, void *addrs)
1147 {
1148 short ioaddr = dev->base_addr;
1149
1150 if(num_addrs) {
1151 outb(3, ioaddr + RECEIVE_MODE_REG);
1152 } else {
1153 outb(2, ioaddr + RECEIVE_MODE_REG);
1154 }
1155 }
1156
1157 static struct enet_statistics *eth16i_get_stats(struct device *dev)
1158 {
1159 struct eth16i_local *lp = (struct eth16i_local *)dev->priv;
1160
1161 return &lp->stats;
1162 }
1163
1164 static void eth16i_select_regbank(unsigned char banknbr, short ioaddr)
1165 {
1166 unsigned char data;
1167
1168 data = inb(ioaddr + CONFIG_REG_1);
1169 outb( ((data & 0xF3) | ( (banknbr & 0x03) << 2)), ioaddr + CONFIG_REG_1);
1170 }
1171
1172 #ifdef MODULE
1173 static char devicename[9] = { 0, };
1174 static struct device dev_eth16i = {
1175 devicename,
1176 0, 0, 0, 0,
1177 0, 0,
1178 0, 0, 0, NULL, eth16i_probe };
1179
1180 int io = 0x2a0;
1181 int irq = 0;
1182
1183 int init_module(void)
1184 {
1185 if(io == 0)
1186 printk("eth16i: You should not use auto-probing with insmod!\n");
1187
1188 dev_eth16i.base_addr = io;
1189 dev_eth16i.irq = irq;
1190 if( register_netdev( &dev_eth16i ) != 0 ) {
1191 printk("eth16i: register_netdev() returned non-zero.\n");
1192 return -EIO;
1193 }
1194
1195 return 0;
1196 }
1197
1198 void cleanup_module(void)
1199 {
1200 if (MOD_IN_USE)
1201 printk("eth16i: Device busy, remove delayed\n");
1202 else
1203 {
1204 unregister_netdev( &dev_eth16i );
1205
1206 free_irq( dev_eth16i.irq );
1207 irq2dev_map[ dev_eth16i.irq ] = NULL;
1208 release_region( dev_eth16i.base_addr, ETH16I_IO_EXTENT );
1209 }
1210 }
1211
1212 #endif
1213
1214