This source file includes following definitions.
- express_probe
- eexp_probe1
- eexp_open
- eexp_send_packet
- eexp_interrupt
- eexp_close
- eexp_get_stats
- set_multicast_list
- read_eeprom
- init_82586_mem
- init_rx_bufs
- hardware_send_packet
- eexp_rx
- 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 static const char *version =
25 "eexpress.c:v0.07 1/19/94 Donald Becker (becker@super.org)\n";
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <linux/module.h>
39
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/types.h>
43 #include <linux/fcntl.h>
44 #include <linux/interrupt.h>
45 #include <linux/ptrace.h>
46 #include <linux/ioport.h>
47 #include <linux/string.h>
48 #include <linux/in.h>
49 #include <asm/system.h>
50 #include <asm/bitops.h>
51 #include <asm/io.h>
52 #include <asm/dma.h>
53 #include <linux/errno.h>
54
55 #include <linux/netdevice.h>
56 #include <linux/etherdevice.h>
57 #include <linux/skbuff.h>
58 #include <linux/malloc.h>
59
60
61 #ifndef NET_DEBUG
62 #define NET_DEBUG 2
63 #endif
64 static unsigned int net_debug = NET_DEBUG;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 #define CMD_EOL 0x8000
85 #define CMD_SUSP 0x4000
86 #define CMD_INTR 0x2000
87
88 enum commands {
89 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
90 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
91
92
93 struct net_local {
94 struct enet_statistics stats;
95 int last_restart;
96 short rx_head;
97 short rx_tail;
98 short tx_head;
99 short tx_cmd_link;
100 short tx_reap;
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 #define DATAPORT 0
132 #define WRITE_PTR 2
133 #define READ_PTR 4
134 #define SIGNAL_CA 6
135 #define SET_IRQ 7
136 #define SHADOW_PTR 8
137 #define MEM_Ctrl 11
138 #define MEM_Page_Ctrl 12
139 #define Config 13
140 #define EEPROM_Ctrl 14
141 #define ID_PORT 15
142
143 #define EEXPRESS_IO_EXTENT 16
144
145
146
147 #define EE_SHIFT_CLK 0x01
148 #define EE_CS 0x02
149 #define EE_DATA_WRITE 0x04
150 #define EE_DATA_READ 0x08
151 #define EE_CTRL_BITS (EE_SHIFT_CLK | EE_CS | EE_DATA_WRITE | EE_DATA_READ)
152 #define ASIC_RESET 0x40
153 #define _586_RESET 0x80
154
155
156 #define SCB_STATUS 0xc008
157 #define SCB_CMD 0xc00A
158 #define CUC_START 0x0100
159 #define CUC_RESUME 0x0200
160 #define CUC_SUSPEND 0x0300
161 #define RX_START 0x0010
162 #define RX_RESUME 0x0020
163 #define RX_SUSPEND 0x0030
164 #define SCB_CBL 0xc00C
165 #define SCB_RFA 0xc00E
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 #define CONFIG_CMD 0x0018
183 #define SET_SA_CMD 0x0024
184 #define SA_OFFSET 0x002A
185 #define IDLELOOP 0x30
186 #define TDR_CMD 0x38
187 #define TDR_TIME 0x3C
188 #define DUMP_CMD 0x40
189 #define DIAG_CMD 0x48
190 #define SET_MC_CMD 0x4E
191 #define DUMP_DATA 0x56
192
193 #define TX_BUF_START 0x0100
194 #define NUM_TX_BUFS 4
195 #define TX_BUF_SIZE 0x0680
196 #define TX_BUF_END 0x2000
197
198 #define RX_BUF_START 0x2000
199 #define RX_BUF_SIZE (0x640)
200 #define RX_BUF_END 0x4000
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 static short init_words[] = {
236 0x0000,
237 0x0000,0x0000,
238 0,0,
239 0x0001,
240 0x0008,0,0,
241
242 0,0xf000|RX_START|CUC_START,
243 CONFIG_CMD,
244 RX_BUF_START,
245 0,0,0,0,
246
247
248 0, CmdConfigure,
249 SET_SA_CMD,
250 0x0804,
251 0x2e40,
252 0,
253
254
255 0, CmdSASetup,
256 SET_MC_CMD,
257 0xaa00,0xb000,0x0bad,
258
259
260 0, CmdNOp, IDLELOOP, 0 ,
261
262
263 0, CmdTDR, IDLELOOP, 0,
264
265
266 0, CmdDump, IDLELOOP, DUMP_DATA,
267
268
269 0, CmdDiagnose, IDLELOOP,
270
271
272 #ifdef initial_text_tx
273 0, CmdMulticastList, DUMP_DATA, 0,
274 #else
275 0, CmdMulticastList, IDLELOOP, 0,
276 #endif
277
278
279 0, CmdTx, DUMP_DATA, DUMP_DATA+8, 0x83ff, -1, DUMP_DATA, 0,
280 };
281
282
283
284 extern int express_probe(struct device *dev);
285
286 static int eexp_probe1(struct device *dev, short ioaddr);
287 static int eexp_open(struct device *dev);
288 static int eexp_send_packet(struct sk_buff *skb, struct device *dev);
289 static void eexp_interrupt(int irq, struct pt_regs *regs);
290 static void eexp_rx(struct device *dev);
291 static int eexp_close(struct device *dev);
292 static struct enet_statistics *eexp_get_stats(struct device *dev);
293 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
294
295 static int read_eeprom(int ioaddr, int location);
296 static void hardware_send_packet(struct device *dev, void *buf, short length);
297 static void init_82586_mem(struct device *dev);
298 static void init_rx_bufs(struct device *dev);
299
300
301
302
303
304
305
306
307 int
308 express_probe(struct device *dev)
309 {
310
311 int *port, ports[] = {0x300, 0x270, 0x320, 0x340, 0};
312 int base_addr = dev->base_addr;
313
314 if (base_addr > 0x1ff)
315 return eexp_probe1(dev, base_addr);
316 else if (base_addr > 0)
317 return ENXIO;
318
319 for (port = &ports[0]; *port; port++) {
320 short id_addr = *port + ID_PORT;
321 unsigned short sum = 0;
322 int i;
323 #ifdef notdef
324 for (i = 16; i > 0; i--)
325 sum += inb(id_addr);
326 printk("EtherExpress ID checksum is %04x.\n", sum);
327 #else
328 for (i = 4; i > 0; i--) {
329 short id_val = inb(id_addr);
330 sum |= (id_val >> 4) << ((id_val & 3) << 2);
331 }
332 #endif
333 if (sum == 0xbaba
334 && eexp_probe1(dev, *port) == 0)
335 return 0;
336 }
337
338 return ENODEV;
339 }
340
341 int eexp_probe1(struct device *dev, short ioaddr)
342 {
343 unsigned short station_addr[3];
344 int i;
345
346 printk("%s: EtherExpress at %#x,", dev->name, ioaddr);
347
348
349
350 station_addr[0] = read_eeprom(ioaddr, 2);
351 station_addr[1] = read_eeprom(ioaddr, 3);
352 station_addr[2] = read_eeprom(ioaddr, 4);
353
354
355 if (station_addr[2] != 0x00aa || (station_addr[1] & 0xff00) != 0x0000) {
356 printk(" rejected (invalid address %04x%04x%04x).\n",
357 station_addr[2], station_addr[1], station_addr[0]);
358 return ENODEV;
359 }
360
361
362 request_region(ioaddr, EEXPRESS_IO_EXTENT, "eexpress");
363 dev->base_addr = ioaddr;
364
365 for (i = 0; i < 6; i++) {
366 dev->dev_addr[i] = ((unsigned char*)station_addr)[5-i];
367 printk(" %02x", dev->dev_addr[i]);
368 }
369
370
371
372 {
373 char irqmap[] = {0, 9, 3, 4, 5, 10, 11, 0};
374 const char *ifmap[] = {"AUI", "BNC", "10baseT"};
375 enum iftype {AUI=0, BNC=1, TP=2};
376 unsigned short setupval = read_eeprom(ioaddr, 0);
377
378 dev->irq = irqmap[setupval >> 13];
379 dev->if_port = (setupval & 0x1000) == 0 ? AUI :
380 read_eeprom(ioaddr, 5) & 0x1 ? TP : BNC;
381 printk(", IRQ %d, Interface %s.\n", dev->irq, ifmap[dev->if_port]);
382
383
384 outb(0x00, ioaddr + SET_IRQ);
385 }
386
387
388 outb(ASIC_RESET, ioaddr + EEPROM_Ctrl);
389
390 if ((dev->mem_start & 0xf) > 0)
391 net_debug = dev->mem_start & 7;
392
393 if (net_debug)
394 printk(version);
395
396
397 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
398 if (dev->priv == NULL)
399 return -ENOMEM;
400 memset(dev->priv, 0, sizeof(struct net_local));
401
402 dev->open = eexp_open;
403 dev->stop = eexp_close;
404 dev->hard_start_xmit = eexp_send_packet;
405 dev->get_stats = eexp_get_stats;
406 dev->set_multicast_list = &set_multicast_list;
407
408
409
410 ether_setup(dev);
411
412 dev->flags&=~IFF_MULTICAST;
413
414 return 0;
415 }
416
417
418
419 static char irqrmap[]={0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0};
420
421 static int
422 eexp_open(struct device *dev)
423 {
424 int ioaddr = dev->base_addr;
425
426 if (dev->irq == 0 || irqrmap[dev->irq] == 0)
427 return -ENXIO;
428
429 if (irq2dev_map[dev->irq] != 0
430
431 || (irq2dev_map[dev->irq] = dev) == 0
432 || request_irq(dev->irq, &eexp_interrupt, 0, "EExpress")) {
433 return -EAGAIN;
434 }
435
436
437 init_82586_mem(dev);
438
439
440 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
441
442 dev->tbusy = 0;
443 dev->interrupt = 0;
444 dev->start = 1;
445 MOD_INC_USE_COUNT;
446 return 0;
447 }
448
449 static int
450 eexp_send_packet(struct sk_buff *skb, struct device *dev)
451 {
452 struct net_local *lp = (struct net_local *)dev->priv;
453 int ioaddr = dev->base_addr;
454
455 if (dev->tbusy) {
456
457
458 int tickssofar = jiffies - dev->trans_start;
459 if (tickssofar < 5)
460 return 1;
461 if (net_debug > 1)
462 printk("%s: transmit timed out, %s? ", dev->name,
463 inw(ioaddr+SCB_STATUS) & 0x8000 ? "IRQ conflict" :
464 "network cable problem");
465 lp->stats.tx_errors++;
466
467 if (lp->last_restart == lp->stats.tx_packets) {
468 if (net_debug > 1) printk("Resetting board.\n");
469
470 init_82586_mem(dev);
471 } else {
472
473 if (net_debug > 1) printk("Kicking board.\n");
474 outw(0xf000|CUC_START|RX_START, ioaddr + SCB_CMD);
475 outb(0, ioaddr + SIGNAL_CA);
476 lp->last_restart = lp->stats.tx_packets;
477 }
478 dev->tbusy=0;
479 dev->trans_start = jiffies;
480 }
481
482
483
484
485 if (skb == NULL) {
486 dev_tint(dev);
487 return 0;
488 }
489
490
491 if (set_bit(0, (void*)&dev->tbusy) != 0)
492 printk("%s: Transmitter access conflict.\n", dev->name);
493 else {
494 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
495 unsigned char *buf = skb->data;
496
497
498 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
499 hardware_send_packet(dev, buf, length);
500 dev->trans_start = jiffies;
501
502 outb(0x08 | irqrmap[dev->irq], ioaddr + SET_IRQ);
503 }
504
505 dev_kfree_skb (skb, FREE_WRITE);
506
507
508 lp->stats.tx_aborted_errors++;
509
510 return 0;
511 }
512
513
514
515 static void
516 eexp_interrupt(int irq, struct pt_regs *regs)
517 {
518 struct device *dev = (struct device *)(irq2dev_map[irq]);
519 struct net_local *lp;
520 int ioaddr, status, boguscount = 0;
521 short ack_cmd;
522
523 if (dev == NULL) {
524 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
525 return;
526 }
527 dev->interrupt = 1;
528
529 ioaddr = dev->base_addr;
530 lp = (struct net_local *)dev->priv;
531
532 status = inw(ioaddr + SCB_STATUS);
533
534 if (net_debug > 4) {
535 printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);
536 }
537
538
539 outb(irqrmap[dev->irq], ioaddr + SET_IRQ);
540
541
542 while (lp->tx_reap != lp->tx_head) {
543 unsigned short tx_status;
544 outw(lp->tx_reap, ioaddr + READ_PTR);
545 tx_status = inw(ioaddr);
546 if (tx_status == 0) {
547 if (net_debug > 5) printk("Couldn't reap %#x.\n", lp->tx_reap);
548 break;
549 }
550 if (tx_status & 0x2000) {
551 lp->stats.tx_packets++;
552 lp->stats.collisions += tx_status & 0xf;
553 dev->tbusy = 0;
554 mark_bh(NET_BH);
555 } else {
556 lp->stats.tx_errors++;
557 if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
558 if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
559 if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
560 if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
561 }
562 if (net_debug > 5)
563 printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
564 lp->tx_reap += TX_BUF_SIZE;
565 if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)
566 lp->tx_reap = TX_BUF_START;
567 if (++boguscount > 4)
568 break;
569 }
570
571 if (status & 0x4000) {
572 if (net_debug > 5)
573 printk("Received packet, rx_head %04x.\n", lp->rx_head);
574 eexp_rx(dev);
575 }
576
577
578 ack_cmd = status & 0xf000;
579
580 if ((status & 0x0700) != 0x0200 && dev->start) {
581 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
582 if (net_debug > 1)
583 printk("%s: Command unit stopped, status %04x, restarting.\n",
584 dev->name, status);
585
586
587 outw(IDLELOOP, ioaddr + WRITE_PTR);
588 outw(0, ioaddr);
589 outw(CmdNOp, ioaddr);
590 outw(IDLELOOP, ioaddr);
591 outw(IDLELOOP, SCB_CBL);
592 lp->tx_cmd_link = IDLELOOP + 4;
593 lp->tx_head = lp->tx_reap = TX_BUF_START;
594
595 outw(saved_write_ptr, ioaddr + WRITE_PTR);
596 ack_cmd |= CUC_START;
597 }
598
599 if ((status & 0x0070) != 0x0040 && dev->start) {
600 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
601
602
603 lp->stats.rx_errors++;
604 if (net_debug > 1) {
605 int cur_rxbuf = RX_BUF_START;
606 printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",
607 dev->name, status, lp->rx_head, lp->rx_tail);
608 while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {
609 int i;
610 printk(" Rx buf at %04x:", cur_rxbuf);
611 outw(cur_rxbuf, ioaddr + READ_PTR);
612 for (i = 0; i < 0x20; i += 2)
613 printk(" %04x", inw(ioaddr));
614 printk(".\n");
615 cur_rxbuf += RX_BUF_SIZE;
616 }
617 }
618 init_rx_bufs(dev);
619 outw(RX_BUF_START, SCB_RFA);
620 outw(saved_write_ptr, ioaddr + WRITE_PTR);
621 ack_cmd |= RX_START;
622 }
623
624 outw(ack_cmd, ioaddr + SCB_CMD);
625 outb(0, ioaddr + SIGNAL_CA);
626
627 if (net_debug > 5) {
628 printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,
629 inw(ioaddr + SCB_CMD));
630 }
631
632 outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);
633 return;
634 }
635
636 static int
637 eexp_close(struct device *dev)
638 {
639 int ioaddr = dev->base_addr;
640
641 dev->tbusy = 1;
642 dev->start = 0;
643
644
645 outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);
646 outb(0, ioaddr + SIGNAL_CA);
647
648
649 outb(0, ioaddr + SET_IRQ);
650
651 free_irq(dev->irq);
652
653 irq2dev_map[dev->irq] = 0;
654
655
656
657 MOD_DEC_USE_COUNT;
658 return 0;
659 }
660
661
662
663 static struct enet_statistics *
664 eexp_get_stats(struct device *dev)
665 {
666 struct net_local *lp = (struct net_local *)dev->priv;
667
668
669
670 return &lp->stats;
671 }
672
673
674
675
676
677
678
679 static void
680 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
681 {
682
683 #if 0
684 short ioaddr = dev->base_addr;
685 if (num_addrs < 0) {
686
687
688 } else if (num_addrs > 0) {
689
690
691 outw(SET_MC_CMD + 6, ioaddr + WRITE_PTR);
692 outw(num_addrs * 6, ioaddr);
693 outsw(ioaddr, addrs, num_addrs*3);
694
695 } else {
696
697
698 outw(99, ioaddr);
699 }
700 #endif
701 }
702
703
704
705
706 #define eeprom_delay() { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }}
707 #define EE_READ_CMD (6 << 6)
708
709 int
710 read_eeprom(int ioaddr, int location)
711 {
712 int i;
713 unsigned short retval = 0;
714 short ee_addr = ioaddr + EEPROM_Ctrl;
715 int read_cmd = location | EE_READ_CMD;
716 short ctrl_val = EE_CS | _586_RESET;
717
718 outb(ctrl_val, ee_addr);
719
720
721 for (i = 8; i >= 0; i--) {
722 short outval = (read_cmd & (1 << i)) ? ctrl_val | EE_DATA_WRITE
723 : ctrl_val;
724 outb(outval, ee_addr);
725 outb(outval | EE_SHIFT_CLK, ee_addr);
726 eeprom_delay();
727 outb(outval, ee_addr);
728 eeprom_delay();
729 }
730 outb(ctrl_val, ee_addr);
731
732 for (i = 16; i > 0; i--) {
733 outb(ctrl_val | EE_SHIFT_CLK, ee_addr); eeprom_delay();
734 retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
735 outb(ctrl_val, ee_addr); eeprom_delay();
736 }
737
738
739 ctrl_val &= ~EE_CS;
740 outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
741 eeprom_delay();
742 outb(ctrl_val, ee_addr);
743 eeprom_delay();
744 return retval;
745 }
746
747 static void
748 init_82586_mem(struct device *dev)
749 {
750 struct net_local *lp = (struct net_local *)dev->priv;
751 short ioaddr = dev->base_addr;
752
753
754
755 outb(inb(ioaddr + Config) | 0x02, ioaddr + Config);
756
757
758 outb(_586_RESET, ioaddr + EEPROM_Ctrl);
759
760
761 outw(0xfff6, ioaddr + WRITE_PTR);
762 outsw(ioaddr, init_words, sizeof(init_words)>>1);
763
764
765 outw(SA_OFFSET, ioaddr + WRITE_PTR);
766 outsw(ioaddr, dev->dev_addr, 3);
767
768
769 #ifdef initial_text_tx
770 lp->tx_cmd_link = DUMP_DATA + 4;
771 #else
772 lp->tx_cmd_link = IDLELOOP + 4;
773 #endif
774 lp->tx_head = lp->tx_reap = TX_BUF_START;
775
776 init_rx_bufs(dev);
777
778
779 outb(0x00, ioaddr + EEPROM_Ctrl);
780
781
782
783 outb(0, ioaddr + SIGNAL_CA);
784
785 {
786 int boguscnt = 50;
787 while (inw(ioaddr + SCB_STATUS) == 0)
788 if (--boguscnt == 0) {
789 printk("%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
790 dev->name, inw(ioaddr + SCB_STATUS), inw(ioaddr + SCB_CMD));
791 break;
792 }
793
794 outb(0, ioaddr + SIGNAL_CA);
795 }
796
797
798 outb(inb(ioaddr + Config) & ~0x02, ioaddr + Config);
799 if (net_debug > 4)
800 printk("%s: Initialized 82586, status %04x.\n", dev->name,
801 inw(ioaddr + SCB_STATUS));
802 return;
803 }
804
805
806 static void init_rx_bufs(struct device *dev)
807 {
808 struct net_local *lp = (struct net_local *)dev->priv;
809 short ioaddr = dev->base_addr;
810
811 int cur_rxbuf = lp->rx_head = RX_BUF_START;
812
813
814 do {
815 outw(cur_rxbuf, ioaddr + WRITE_PTR);
816 outw(0x0000, ioaddr);
817 outw(0x0000, ioaddr);
818 outw(cur_rxbuf + RX_BUF_SIZE, ioaddr);
819 outw(cur_rxbuf + 22, ioaddr);
820 outw(0xFeed, ioaddr);
821 outw(0xF00d, ioaddr);
822 outw(0xF001, ioaddr);
823 outw(0x0505, ioaddr);
824 outw(0x2424, ioaddr);
825 outw(0x6565, ioaddr);
826 outw(0xdeaf, ioaddr);
827
828 outw(0x0000, ioaddr);
829 outw(-1, ioaddr);
830 outw(cur_rxbuf + 0x20, ioaddr);
831 outw(0x0000, ioaddr);
832
833 outw(0x8000 + RX_BUF_SIZE-0x20, ioaddr);
834
835 lp->rx_tail = cur_rxbuf;
836 cur_rxbuf += RX_BUF_SIZE;
837 } while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE);
838
839
840
841 outw(lp->rx_tail + 2, ioaddr + WRITE_PTR);
842 outw(0xC000, ioaddr);
843 outw(lp->rx_head, ioaddr);
844 }
845
846 static void
847 hardware_send_packet(struct device *dev, void *buf, short length)
848 {
849 struct net_local *lp = (struct net_local *)dev->priv;
850 short ioaddr = dev->base_addr;
851 short tx_block = lp->tx_head;
852
853
854 outw(tx_block, ioaddr + WRITE_PTR);
855 outw(0x0000, ioaddr);
856 outw(CMD_INTR|CmdTx, ioaddr);
857 outw(tx_block+16, ioaddr);
858 outw(tx_block+8, ioaddr);
859
860
861 outw(length | 0x8000, ioaddr);
862 outw(-1, ioaddr);
863 outw(tx_block+22, ioaddr);
864 outw(0x0000, ioaddr);
865
866
867 outw(0x0000, ioaddr);
868 outw(CmdNOp, ioaddr);
869 outw(tx_block+16, ioaddr);
870
871
872
873 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
874
875
876 outw(lp->tx_cmd_link, ioaddr + WRITE_PTR);
877 outw(tx_block, ioaddr);
878 lp->tx_cmd_link = tx_block + 20;
879
880
881 lp->tx_head = tx_block + TX_BUF_SIZE;
882 if (lp->tx_head > TX_BUF_END - TX_BUF_SIZE)
883 lp->tx_head = TX_BUF_START;
884
885 if (net_debug > 4) {
886 printk("%s: EExp @%x send length = %d, tx_block %3x, next %3x, "
887 "reap %4x status %4.4x.\n", dev->name, ioaddr, length,
888 tx_block, lp->tx_head, lp->tx_reap, inw(ioaddr + SCB_STATUS));
889 }
890
891 if (lp->tx_head != lp->tx_reap)
892 dev->tbusy = 0;
893 }
894
895 static void
896 eexp_rx(struct device *dev)
897 {
898 struct net_local *lp = (struct net_local *)dev->priv;
899 short ioaddr = dev->base_addr;
900 short saved_write_ptr = inw(ioaddr + WRITE_PTR);
901 short rx_head = lp->rx_head;
902 short rx_tail = lp->rx_tail;
903 short boguscount = 10;
904 short frame_status;
905
906
907 outw(rx_head, ioaddr + READ_PTR);
908 while ((frame_status = inw(ioaddr)) < 0) {
909 short rfd_cmd = inw(ioaddr);
910 short next_rx_frame = inw(ioaddr);
911 short data_buffer_addr = inw(ioaddr);
912 short pkt_len;
913
914
915 outw(data_buffer_addr, ioaddr + READ_PTR);
916 pkt_len = inw(ioaddr);
917
918 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22
919 || (pkt_len & 0xC000) != 0xC000) {
920 printk("%s: Rx frame at %#x corrupted, status %04x cmd %04x"
921 "next %04x data-buf @%04x %04x.\n", dev->name, rx_head,
922 frame_status, rfd_cmd, next_rx_frame, data_buffer_addr,
923 pkt_len);
924 } else if ((frame_status & 0x2000) == 0) {
925
926 lp->stats.rx_errors++;
927 if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
928 if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
929 if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
930 if (frame_status & 0x0100) lp->stats.rx_over_errors++;
931 if (frame_status & 0x0080) lp->stats.rx_length_errors++;
932 } else {
933
934 struct sk_buff *skb;
935
936 pkt_len &= 0x3fff;
937 skb = dev_alloc_skb(pkt_len+2);
938 if (skb == NULL) {
939 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
940 lp->stats.rx_dropped++;
941 break;
942 }
943 skb->dev = dev;
944 skb_reserve(skb,2);
945
946 outw(data_buffer_addr + 10, ioaddr + READ_PTR);
947
948 insw(ioaddr, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
949
950 skb->protocol=eth_type_trans(skb,dev);
951 netif_rx(skb);
952 lp->stats.rx_packets++;
953 }
954
955
956 outw(rx_head, ioaddr + WRITE_PTR);
957 outw(0x0000, ioaddr);
958 outw(0xC000, ioaddr);
959 #ifndef final_version
960 if (next_rx_frame != rx_head + RX_BUF_SIZE
961 && next_rx_frame != RX_BUF_START) {
962 printk("%s: Rx next frame at %#x is %#x instead of %#x.\n", dev->name,
963 rx_head, next_rx_frame, rx_head + RX_BUF_SIZE);
964 next_rx_frame = rx_head + RX_BUF_SIZE;
965 if (next_rx_frame >= RX_BUF_END - RX_BUF_SIZE)
966 next_rx_frame = RX_BUF_START;
967 }
968 #endif
969 outw(rx_tail+2, ioaddr + WRITE_PTR);
970 outw(0x0000, ioaddr);
971
972 #ifndef final_version
973 outw(rx_tail+4, ioaddr + READ_PTR);
974 if (inw(ioaddr) != rx_head) {
975 printk("%s: Rx buf link mismatch, at %04x link %04x instead of %04x.\n",
976 dev->name, rx_tail, (outw(rx_tail+4, ioaddr + READ_PTR),inw(ioaddr)),
977 rx_head);
978 outw(rx_head, ioaddr);
979 }
980 #endif
981
982 rx_tail = rx_head;
983 rx_head = next_rx_frame;
984 if (--boguscount == 0)
985 break;
986 outw(rx_head, ioaddr + READ_PTR);
987 }
988
989 lp->rx_head = rx_head;
990 lp->rx_tail = rx_tail;
991
992
993 outw(saved_write_ptr, ioaddr + WRITE_PTR);
994 }
995
996 #ifdef MODULE
997 static char devicename[9] = { 0, };
998 static struct device dev_eexpress = {
999 devicename,
1000 0, 0, 0, 0,
1001 0, 0,
1002 0, 0, 0, NULL, express_probe };
1003
1004
1005 static int irq=0x300;
1006 static int io=0;
1007
1008 int
1009 init_module(void)
1010 {
1011 if (io == 0)
1012 printk("eexpress: You should not use auto-probing with insmod!\n");
1013 dev_eexpress.base_addr=io;
1014 dev_eexpress.irq=irq;
1015 if (register_netdev(&dev_eexpress) != 0)
1016 return -EIO;
1017 return 0;
1018 }
1019
1020 void
1021 cleanup_module(void)
1022 {
1023 unregister_netdev(&dev_eexpress);
1024 kfree_s(dev_eexpress.priv,sizeof(struct net_local));
1025 dev_eexpress.priv=NULL;
1026
1027
1028 release_region(dev_eexpress.base_addr, EEXPRESS_IO_EXTENT);
1029 }
1030 #endif
1031
1032
1033
1034
1035
1036
1037
1038