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